@limcpf/everything-is-a-markdown 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/build.ts +26 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@limcpf/everything-is-a-markdown",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {
package/src/build.ts CHANGED
@@ -612,6 +612,19 @@ function sortTree(nodes: TreeNode[]): TreeNode[] {
612
612
  return nodes;
613
613
  }
614
614
 
615
+ function parseDateToEpochMs(value: string | undefined): number | null {
616
+ if (!value) {
617
+ return null;
618
+ }
619
+
620
+ const parsed = Date.parse(value);
621
+ return Number.isFinite(parsed) ? parsed : null;
622
+ }
623
+
624
+ function getRecentSortEpochMs(doc: DocRecord): number {
625
+ return parseDateToEpochMs(doc.date) ?? doc.mtimeMs;
626
+ }
627
+
615
628
  function buildPinnedMenuFolder(docs: DocRecord[], options: BuildOptions): FolderNode | null {
616
629
  if (!options.pinnedMenu) {
617
630
  return null;
@@ -673,7 +686,19 @@ function buildTree(docs: DocRecord[], options: BuildOptions): TreeNode[] {
673
686
  sortTree(root.children);
674
687
 
675
688
  const recentChildren = [...docs]
676
- .sort((a, b) => b.mtimeMs - a.mtimeMs)
689
+ .sort((left, right) => {
690
+ const byDate = getRecentSortEpochMs(right) - getRecentSortEpochMs(left);
691
+ if (byDate !== 0) {
692
+ return byDate;
693
+ }
694
+
695
+ const byMtime = right.mtimeMs - left.mtimeMs;
696
+ if (byMtime !== 0) {
697
+ return byMtime;
698
+ }
699
+
700
+ return left.relNoExt.localeCompare(right.relNoExt, "ko-KR");
701
+ })
677
702
  .slice(0, options.recentLimit)
678
703
  .map((doc) => fileNodeFromDoc(doc));
679
704