-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rename markdown to blog * Multi-page docs * Ignore missing ID for now * heading * Add code snippets(temporary) * /docs redirects to introduction * Remove ukraine petition * OnThisPage * Remove console.log * Update deps * Fix accessibility warning * Update site-kit
- Loading branch information
Showing
24 changed files
with
2,416 additions
and
692 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,73 @@ | ||
import fs from 'fs'; | ||
import { extract_frontmatter } from '../markdown'; | ||
import { transform } from './marked'; | ||
|
||
/** | ||
* @returns {import('./types').BlogPostSummary[]} | ||
*/ | ||
export function get_index() { | ||
return fs | ||
.readdirSync('content/blog') | ||
.reverse() | ||
.map((file) => { | ||
if (!file.endsWith('.md')) return; | ||
|
||
const { date, slug } = get_date_and_slug(file); | ||
|
||
const content = fs.readFileSync(`content/blog/${file}`, 'utf-8'); | ||
const { metadata } = extract_frontmatter(content); | ||
|
||
return { | ||
slug, | ||
date, | ||
title: metadata.title, | ||
description: metadata.description, | ||
draft: !!metadata.draft, | ||
}; | ||
}); | ||
} | ||
|
||
/** | ||
* @param {string} slug | ||
* @returns {import('./types').BlogPost} | ||
*/ | ||
export function get_post(slug) { | ||
for (const file of fs.readdirSync('content/blog')) { | ||
if (!file.endsWith('.md')) continue; | ||
if (file.slice(11, -3) !== slug) continue; | ||
|
||
const { date, date_formatted } = get_date_and_slug(file); | ||
|
||
const content = fs.readFileSync(`content/blog/${file}`, 'utf-8'); | ||
const { metadata, body } = extract_frontmatter(content); | ||
|
||
return { | ||
date, | ||
date_formatted, | ||
title: metadata.title, | ||
description: metadata.description, | ||
author: { | ||
name: metadata.author, | ||
url: metadata.authorURL, | ||
}, | ||
draft: !!metadata.draft, | ||
content: transform(body), | ||
}; | ||
} | ||
} | ||
|
||
/** @param {string} filename */ | ||
function get_date_and_slug(filename) { | ||
const match = /^(\d{4}-\d{2}-\d{2})-(.+)\.md$/.exec(filename); | ||
if (!match) throw new Error(`Invalid filename for blog: '${filename}'`); | ||
|
||
const [, date, slug] = match; | ||
const [y, m, d] = date.split('-'); | ||
const date_formatted = `${months[+m - 1]} ${+d} ${y}`; | ||
|
||
return { date, date_formatted, slug }; | ||
} | ||
|
||
const months = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' '); | ||
|
||
function format_date(date) {} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
6934931
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
svelte-dev-2 – ./
svelte-dev-2.vercel.app
svelte-dev-2-git-sites-svelte.vercel.app
svelte-dev-2-svelte.vercel.app