Skip to content

Commit

Permalink
refactor: move all logic in old static to new core
Browse files Browse the repository at this point in the history
  • Loading branch information
RyoJerryYu committed Apr 27, 2024
1 parent 447ce21 commit 8dc33fa
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 115 deletions.
30 changes: 11 additions & 19 deletions src/statics/index.ts → src/core/indexing/indexing-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,26 @@
* And ensure: init once, no modification after init.
*/

import { AliasIndex } from "@/core/indexing/index-building/alias-index-builder";
import { clipDataFromPool } from "@/core/indexing/index-building/clip-data-index-builder";
import { PrevNextIndex } from "@/core/indexing/index-building/prev-next-index-builder";
import { TagIndex } from "@/core/indexing/index-building/tag-index-builder";
import { devReloadingChain, pipeline } from "@/core/indexing/indexing-settings";
import { collectMetaForFilePath } from "@/core/indexing/meta-collecting/meta-collecting";
import {
PipelineResult,
executePipeline,
} from "@/core/indexing/pipeline/pipeline";
import {
ResourceMap,
getResourceMap,
} from "@/core/indexing/pipeline/resource-pool";
import { PagePathMapping, PostMeta } from "@/core/types/indexing";
import { PagePathMapping, PostMeta } from "../types/indexing";
import { AliasIndex } from "./index-building/alias-index-builder";
import { clipDataFromPool } from "./index-building/clip-data-index-builder";
import { PrevNextIndex } from "./index-building/prev-next-index-builder";
import { TagIndex } from "./index-building/tag-index-builder";
import { devReloadingChain, pipeline } from "./indexing-settings";
import { collectMetaForFilePath } from "./meta-collecting/meta-collecting";
import { PipelineResult, executePipeline } from "./pipeline/pipeline";
import { ResourceMap, getResourceMap } from "./pipeline/resource-pool";

const pipline = pipeline;
/**
* The module variable as a lazy init singleton
* Init once, and all types of caches are inited.
*/
type Cache = PipelineResult;
let cache: Cache | undefined = undefined;
let cache: PipelineResult | undefined = undefined;
export const initCache = async () => {
if (cache) {
return cache;
}
cache = await executePipeline(pipline);
cache = await executePipeline(pipeline);

return cache;
};
Expand Down
12 changes: 6 additions & 6 deletions src/pages/articles/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import Comments from "@/components/Comments";
import Post from "@/components/Post";
import { PrevNextInfo } from "@/core/indexing/index-building/prev-next-index-builder";
import { TagInfo } from "@/core/indexing/index-building/tag-index-builder";
import { articlePostPathMapper } from "@/core/indexing/indexing-settings";
import { PostMeta } from "@/core/types/indexing";
import DefaultLayout from "@/layouts/DefaultLayout";
import { Description, SEOObject, Title } from "@/layouts/UniversalHead";
import parseMdx from "@/plugins";
import {
articleResourceMap,
getPostMetaOrReload,
getPrevNextIndex,
getTagIndex,
initCache,
} from "@/statics";
} from "@/core/indexing/indexing-cache";
import { articlePostPathMapper } from "@/core/indexing/indexing-settings";
import { PostMeta } from "@/core/types/indexing";
import DefaultLayout from "@/layouts/DefaultLayout";
import { Description, SEOObject, Title } from "@/layouts/UniversalHead";
import parseMdx from "@/plugins";
import { GetStaticPaths, GetStaticProps } from "next";
import { MDXRemoteSerializeResult } from "next-mdx-remote";

Expand Down
10 changes: 5 additions & 5 deletions src/pages/articles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import {
TagInfo,
tagInfoListToMap,
} from "@/core/indexing/index-building/tag-index-builder";
import { PostResource } from "@/core/types/indexing";
import DefaultLayout from "@/layouts/DefaultLayout";
import MainWidth from "@/layouts/MainWidth";
import { Title } from "@/layouts/UniversalHead";
import {
articleResourceMap,
getPrevNextIndex,
getTagIndex,
initCache,
} from "@/statics";
} from "@/core/indexing/indexing-cache";
import { PostResource } from "@/core/types/indexing";
import DefaultLayout from "@/layouts/DefaultLayout";
import MainWidth from "@/layouts/MainWidth";
import { Title } from "@/layouts/UniversalHead";
import { GetStaticProps } from "next";

export const getStaticProps: GetStaticProps<ArticlesProps> = async () => {
Expand Down
6 changes: 5 additions & 1 deletion src/pages/clips/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import {
TagInfo,
tagInfoListToMap,
} from "@/core/indexing/index-building/tag-index-builder";
import {
getClipData,
getTagIndex,
initCache,
} from "@/core/indexing/indexing-cache";
import { PostResource } from "@/core/types/indexing";
import DefaultLayout from "@/layouts/DefaultLayout";
import MainWidth from "@/layouts/MainWidth";
import { Title } from "@/layouts/UniversalHead";
import { getClipData, getTagIndex, initCache } from "@/statics";
import { GetStaticProps } from "next";

type ClipsProps = {
Expand Down
12 changes: 6 additions & 6 deletions src/pages/ideas/[slug].tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import Post from "@/components/Post";
import { PrevNextInfo } from "@/core/indexing/index-building/prev-next-index-builder";
import { TagInfo } from "@/core/indexing/index-building/tag-index-builder";
import { ideaPostPathMapper } from "@/core/indexing/indexing-settings";
import { PostMeta } from "@/core/types/indexing";
import DefaultLayout from "@/layouts/DefaultLayout";
import { Description, Title } from "@/layouts/UniversalHead";
import parseMdx from "@/plugins";
import {
getPostMetaOrReload,
getPrevNextIndex,
getTagIndex,
ideaResourceMap,
initCache,
} from "@/statics";
} from "@/core/indexing/indexing-cache";
import { ideaPostPathMapper } from "@/core/indexing/indexing-settings";
import { PostMeta } from "@/core/types/indexing";
import DefaultLayout from "@/layouts/DefaultLayout";
import { Description, Title } from "@/layouts/UniversalHead";
import parseMdx from "@/plugins";
import { GetStaticPaths, GetStaticProps } from "next";
import { MDXRemoteSerializeResult } from "next-mdx-remote";

Expand Down
10 changes: 5 additions & 5 deletions src/pages/ideas/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import {
TagInfo,
tagInfoListToMap,
} from "@/core/indexing/index-building/tag-index-builder";
import { PostResource } from "@/core/types/indexing";
import DefaultLayout from "@/layouts/DefaultLayout";
import MainWidth from "@/layouts/MainWidth";
import { Title } from "@/layouts/UniversalHead";
import {
getPrevNextIndex,
getTagIndex,
ideaResourceMap,
initCache,
} from "@/statics";
} from "@/core/indexing/indexing-cache";
import { PostResource } from "@/core/types/indexing";
import DefaultLayout from "@/layouts/DefaultLayout";
import MainWidth from "@/layouts/MainWidth";
import { Title } from "@/layouts/UniversalHead";
import { GetStaticProps } from "next";

type IdeasProps = {
Expand Down
12 changes: 6 additions & 6 deletions src/pages/tags/[tag].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import PostList from "@/components/PostList";
import TagSelector from "@/components/TagSelector";
import { sortPostsByDate } from "@/core/indexing/index-building/prev-next-index-builder";
import { TagInfo } from "@/core/indexing/index-building/tag-index-builder";
import {
articleResourceMap,
getTagIndex,
ideaResourceMap,
initCache,
} from "@/core/indexing/indexing-cache";
import {
PagePathMapping,
PostMeta,
Expand All @@ -11,12 +17,6 @@ import {
import DefaultLayout from "@/layouts/DefaultLayout";
import MainWidth from "@/layouts/MainWidth";
import { Title } from "@/layouts/UniversalHead";
import {
articleResourceMap,
getTagIndex,
ideaResourceMap,
initCache,
} from "@/statics";
import { GetStaticPaths, GetStaticProps } from "next";

export const getStaticPaths: GetStaticPaths = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tags/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import TagSelector from "@/components/TagSelector";
import { TagInfo } from "@/core/indexing/index-building/tag-index-builder";
import { getTagIndex, initCache } from "@/core/indexing/indexing-cache";
import DefaultLayout from "@/layouts/DefaultLayout";
import MainWidth from "@/layouts/MainWidth";
import { Title } from "@/layouts/UniversalHead";
import { getTagIndex, initCache } from "@/statics";
import { GetStaticProps } from "next";

type TagsProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/remark-obsidian-rich.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getAliasIndex } from "@/statics";
import { getAliasIndex } from "@/core/indexing/indexing-cache";
import { BASE_PATH } from "@/utils/env-var";
import { Paragraph, Text } from "mdast";
import { MdxJsxFlowElement } from "mdast-util-mdx-jsx";
Expand Down
65 changes: 0 additions & 65 deletions src/statics/README.md

This file was deleted.

0 comments on commit 8dc33fa

Please sign in to comment.