Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Recursively add articles in content/posts #17

Closed
sauricat opened this issue Nov 8, 2024 · 4 comments · Fixed by #18
Closed

[Feature Request] Recursively add articles in content/posts #17

sauricat opened this issue Nov 8, 2024 · 4 comments · Fixed by #18

Comments

@sauricat
Copy link
Member

sauricat commented Nov 8, 2024

I am thinking of the possibility of dividing articles into content/posts into smaller separate directories, such as notifications & announcements, docs for one-among.us, docs for local community, etc.

The official implement of this requires manually adding items in content/.vitepress/config.ts, while thanks to 云依 we have a content/.vitepress/theme/utils/getPostList.ts.

const getPostList = (locale?: string) =>
readdirSync(locale ? `./content/${locale}/posts` : './content/posts')
.map((file) => {
const [fileName, ext] = file.split('.');
if (ext !== 'md') return null;
const fileContent = readFileSync(
locale ? `./content/${locale}/posts/${file}` : `./content/posts/${file}`,
'utf-8',
);
const { metadata } = metadataParser(fileContent);
if (!metadata?.title) return null;
let date;
if (metadata?.date) {
date = Number(new Date(metadata.date));
} else {
date = statSync(
locale ? `./content/${locale}/posts/${file}` : `./content/posts/${file}`,
).ctimeMs;
}
return {
text: metadata.title as string,
link: locale ? `/${locale}/posts/${fileName}` : `/posts/${fileName}`,
time: date,
};
})
.filter((item) => item !== null)
.sort((a, b) => b.time - a.time)
.map(({ text, link }) => ({ text, link }));

What do you think about rewriting this? Also, there must be something to update accordingly in content/posts/index.vue.

import { data as posts } from '../.vitepress/theme/utils/getPostList.data';

@sauricat
Copy link
Member Author

sauricat commented Nov 8, 2024

Also, content/${locale}/posts.

@BeiyanYunyi
Copy link
Member

pending.

@BeiyanYunyi
Copy link
Member

content/.vitepress/theme/utils/getPostList.ts have been not used since getPostList.data.ts was introduced. Deleting it is safe.

@BeiyanYunyi
Copy link
Member

BeiyanYunyi commented Nov 18, 2024

What're you requesting for? A auto-generated sidebar, or make post list (such as content/zh-Hans/posts/index.vue) available in recurred folders?

The former has been implemented in #18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants