Skip to content

Commit bd79751

Browse files
committed
Add markdown links to docs
1 parent 071da58 commit bd79751

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

www/routes/docs/[...slug].tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ const pattern = new URLPattern({ pathname: "/:version/:page*" });
5858

5959
export const handlers = handler({
6060
async GET(ctx): Promise<{ data: Data } | Response> {
61-
const slug = ctx.params.slug;
61+
let slug = ctx.params.slug;
62+
63+
// `/docs/<path>.md` serves the raw markdown source for that page.
64+
const rawMarkdown = slug.endsWith(".md");
65+
if (rawMarkdown) slug = slug.slice(0, -3);
6266

6367
// Check if the slug is the index page of a version tag
6468
if (TABLE_OF_CONTENTS[slug]) {
@@ -134,6 +138,12 @@ export const handlers = handler({
134138
const fileContent = await loadMarkdown();
135139
const { body, attrs } = frontMatter<Record<string, unknown>>(fileContent);
136140

141+
if (rawMarkdown) {
142+
return new Response(body, {
143+
headers: { "content-type": "text/markdown; charset=utf-8" },
144+
});
145+
}
146+
137147
return {
138148
data: {
139149
page: {
@@ -225,7 +235,7 @@ export default definePage(function DocsPage(props) {
225235
/>
226236
</div>
227237
<hr />
228-
<div class="px-4 md:px-0 flex justify-between my-6">
238+
<div class="px-4 md:px-0 flex flex-wrap gap-3 justify-between my-6">
229239
<a
230240
href={`https://github.com/denoland/fresh/edit/main/${page.file}`}
231241
class="text-gray-700 dark:text-gray-200 text-md flex items-center bg-[#ebedf0] dark:bg-[#2c2d39] px-4 py-2 rounded-sm hover:bg-gray-200 dark:hover:bg-[#36394c] transition-colors"
@@ -235,6 +245,12 @@ export default definePage(function DocsPage(props) {
235245
<span class="mr-2 inline-flex">Edit this page</span>
236246
<Icons.GitHub />
237247
</a>
248+
<a
249+
href={`${props.url.pathname}.md`}
250+
class="text-gray-700 dark:text-gray-200 text-md flex items-center bg-[#ebedf0] dark:bg-[#2c2d39] px-4 py-2 rounded-sm hover:bg-gray-200 dark:hover:bg-[#36394c] transition-colors"
251+
>
252+
View as Markdown
253+
</a>
238254
</div>
239255
</div>
240256
</div>

0 commit comments

Comments
 (0)