Skip to content

Commit

Permalink
read the frontmatter (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirSa12 authored Nov 23, 2023
1 parent 735bfdb commit 4c2734c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
34 changes: 34 additions & 0 deletions packages/docs/src/components/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@ import { GlobalStore } from '../../context';
import { CloseIcon } from '../svgs/close-icon';
import styles from './sidebar.css?inline';

const markdownItems = Object.fromEntries(
await Promise.all(
Object.entries(import.meta.glob<{ frontmatter?: MDX }>('../../routes/**/*.{md,mdx}')).map(
async ([k, v]) => {
// console.log(k, (await v())?.frontmatter);
return [
k
.replace('../../routes', '')
.replace('(qwikcity)/', '')
.replace('(qwik)/', '')
.replaceAll(/([()])/g, '')
.replace('index.mdx', '')
.replace('index.md', ''),
await v(),
] as const;
}
)
)
);

type MDX = {
title: string;
contributors: string[];
created_at: string;
updated_at: string;
};

export const SideBar = component$((props: { allOpen?: boolean }) => {
useStyles$(styles);

Expand Down Expand Up @@ -59,6 +86,13 @@ export function Items({
}}
>
{item.text}
{markdownItems[item.href!]?.frontmatter?.updated_at
? new Date(markdownItems[item.href!]?.frontmatter?.updated_at!).getTime() +
5 * 24 * 60 * 60 * 1000 >
new Date().getTime()
? 'new'
: null
: null}
</a>
)}
</li>
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"incremental": true,
"target": "ES2020",
"module": "ES2020",
"target": "ES2022",
"module": "ES2022",
"lib": ["es2021", "DOM", "webworker", "DOM.Iterable"],
"resolveJsonModule": true,
"jsx": "react-jsx",
Expand Down

0 comments on commit 4c2734c

Please sign in to comment.