-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Masaki Nakano
authored and
Masaki Nakano
committed
Jul 3, 2024
1 parent
9b1526b
commit 164daa8
Showing
17 changed files
with
538 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { staticAdapter } from "@builder.io/qwik-city/adapters/static/vite"; | ||
import { extendConfig } from "@builder.io/qwik-city/vite"; | ||
import baseConfig from "../../vite.config"; | ||
|
||
export default extendConfig(baseConfig, () => { | ||
return { | ||
build: { | ||
ssr: true, | ||
rollupOptions: { | ||
input: ["@qwik-city-plan"], | ||
}, | ||
}, | ||
plugins: [ | ||
staticAdapter({ | ||
origin: "https://yoursite.qwik.dev", | ||
}), | ||
], | ||
}; | ||
}); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Resource, component$, useResource$ } from "@builder.io/qwik"; | ||
import { | ||
type BundledLanguage, | ||
codeToHtml, | ||
type StringLiteralUnion, | ||
type SpecialLanguage, | ||
} from "shiki"; | ||
|
||
export interface Props { | ||
lang?: StringLiteralUnion<BundledLanguage | SpecialLanguage>; | ||
text: string; | ||
} | ||
|
||
export default component$((props: Props) => { | ||
const codeResource = useResource$<string>(async () => { | ||
if (props.lang) { | ||
return codeToHtml(props.text, { | ||
lang: props.lang, | ||
themes: { | ||
dark: "github-dark-dimmed", | ||
light: "github-light", | ||
}, | ||
}); | ||
} else { | ||
return `<code>${props.text}</code>`; | ||
} | ||
}); | ||
return ( | ||
<figure> | ||
<Resource | ||
value={codeResource} | ||
onPending={() => <pre></pre>} | ||
onResolved={(text) => <div dangerouslySetInnerHTML={text} />} | ||
onRejected={(err) => <div>{JSON.stringify(err)}</div>} | ||
></Resource> | ||
</figure> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { component$ } from "@builder.io/qwik"; | ||
import type * as MdAst from "mdast"; | ||
import RootContent from "~/components/md/root-content"; | ||
|
||
export interface Props { | ||
root: MdAst.Root; | ||
} | ||
|
||
function key(base: unknown): string { | ||
return JSON.stringify(base); | ||
} | ||
|
||
export default component$((props: Props) => { | ||
return ( | ||
<article> | ||
{props.root.children.map((node) => ( | ||
<RootContent key={key(node.position)} node={node} /> | ||
))} | ||
</article> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { Link } from "@builder.io/qwik-city"; | ||
import type * as MdAst from "mdast"; | ||
import CodeBlock from "./code-block"; | ||
|
||
export function key(node: MdAst.RootContent): string { | ||
return JSON.stringify(node.position); | ||
} | ||
|
||
const RootContent = (props: { node: MdAst.RootContent }) => { | ||
switch (props.node.type) { | ||
case "blockquote": | ||
return ( | ||
<blockquote> | ||
{props.node.children.map((node) => ( | ||
<RootContent key={key(node)} node={node} /> | ||
))} | ||
</blockquote> | ||
); | ||
case "paragraph": | ||
return ( | ||
<p> | ||
{props.node.children.map((node) => ( | ||
<RootContent key={key(node)} node={node} /> | ||
))} | ||
</p> | ||
); | ||
case "section": | ||
return ( | ||
<section> | ||
{props.node.children.map((node) => ( | ||
<RootContent key={key(node)} node={node} /> | ||
))} | ||
</section> | ||
); | ||
case "text": | ||
return props.node.value; | ||
case "inlineCode": | ||
return <code>{props.node.value}</code>; | ||
case "heading": | ||
const inner = props.node.children.map((node) => ( | ||
<RootContent key={key(node)} node={node} /> | ||
)); | ||
switch (props.node.depth) { | ||
case 1: | ||
return <h1>{inner}</h1>; | ||
case 2: | ||
return <h2>{inner}</h2>; | ||
case 3: | ||
return <h3>{inner}</h3>; | ||
case 4: | ||
return <h4>{inner}</h4>; | ||
case 5: | ||
return <h5>{inner}</h5>; | ||
case 6: | ||
return <h6>{inner}</h6>; | ||
} | ||
return null; | ||
case "break": | ||
return <br />; | ||
case "link": | ||
return ( | ||
<Link href={props.node.url}> | ||
{props.node.children.map((node) => ( | ||
<RootContent key={key(node)} node={node} /> | ||
))} | ||
</Link> | ||
); | ||
case "code": | ||
return ( | ||
<CodeBlock | ||
text={props.node.value} | ||
lang={props.node.lang || undefined} | ||
/> | ||
); | ||
case "list": | ||
if (props.node.ordered) { | ||
return ( | ||
<ol> | ||
{props.node.children.map((node) => ( | ||
<RootContent node={node} key={key(node)} /> | ||
))} | ||
</ol> | ||
); | ||
} else { | ||
return ( | ||
<ul> | ||
{props.node.children.map((node) => ( | ||
<RootContent node={node} key={key(node)} /> | ||
))} | ||
</ul> | ||
); | ||
} | ||
case "listItem": | ||
return ( | ||
<li> | ||
{props.node.children.map((node) => ( | ||
<RootContent node={node} key={key(node)} /> | ||
))} | ||
</li> | ||
); | ||
case "strong": | ||
return ( | ||
<strong> | ||
{props.node.children.map((node) => ( | ||
<RootContent node={node} key={key(node)} /> | ||
))} | ||
</strong> | ||
); | ||
default: | ||
return JSON.stringify(props.node); | ||
} | ||
}; | ||
|
||
export default RootContent; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { component$ } from "@builder.io/qwik"; | ||
import { | ||
routeLoader$, | ||
type StaticGenerateHandler, | ||
} from "@builder.io/qwik-city"; | ||
import { post as posts } from "#site/content"; | ||
import Markdown from "~/components/md"; | ||
|
||
export const usePost = routeLoader$(async (event) => { | ||
return posts.find((post) => post.slug === event.params.slug); | ||
}); | ||
|
||
export default component$(() => { | ||
const post = usePost(); | ||
if (post.value) { | ||
return <Markdown root={post.value.content} />; | ||
} else { | ||
return <article></article>; | ||
} | ||
}); | ||
|
||
export const onStaticSiteGenerate: StaticGenerateHandler = async () => { | ||
return { | ||
params: posts.map((post) => ({ | ||
slug: post.slug, | ||
})), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,47 @@ | ||
// @ts-check | ||
|
||
import { defineConfig,s } from "velite"; | ||
import rehypePrettyCode from "rehype-pretty-code"; | ||
import remarkGemoji from "remark-gemoji"; | ||
import remarkGfm from "remark-gfm"; | ||
import remarkMath from "remark-math"; | ||
import remarkParse from "remark-parse"; | ||
import remarkSectionize from "remark-sectionize"; | ||
import { unified } from "unified"; | ||
import { defineConfig, s } from "velite"; | ||
|
||
const parser = unified() | ||
.use(remarkParse) | ||
.use(remarkGfm) | ||
.use(remarkMath) | ||
.use(remarkGemoji) | ||
.use(rehypePrettyCode) | ||
.use(remarkSectionize); | ||
|
||
export default defineConfig({ | ||
collections: { | ||
post: { | ||
name: "post", | ||
pattern: "**/*.md", | ||
schema: s.object({ | ||
title: s.string(), | ||
date: s.string(), | ||
modified: s.string().nullish(), | ||
description: s.string(), | ||
publish: s.boolean(), | ||
tags: s.array(s.string()), | ||
content: s.custom().transform((_, {meta}) => meta.content), | ||
excerpt: s.excerpt() | ||
}) | ||
} | ||
} | ||
schema: s | ||
.object({ | ||
title: s.string(), | ||
date: s.string(), | ||
modified: s.string().nullish(), | ||
description: s.string(), | ||
publish: s.boolean(), | ||
tags: s.array(s.string()), | ||
content: s | ||
.custom() | ||
.transform((_, { meta }) => parser.parse(meta.content)), | ||
excerpt: s.excerpt(), | ||
}) | ||
.transform((data, { meta }) => { | ||
const slug = /\d{4}\/.+\.md$/.exec(meta.path)?.[1]; | ||
return { | ||
...data, | ||
slug: slug || "", | ||
}; | ||
}), | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.