Move blog to site/content

pull/8289/head
Puru Vijay 4 years ago
parent 92830b077b
commit 67e3f85718

@ -2,19 +2,21 @@ import fs from 'fs';
import { extract_frontmatter } from '../markdown'; import { extract_frontmatter } from '../markdown';
import { transform } from './marked'; import { transform } from './marked';
const base = '../../site/content/blog';
/** /**
* @returns {import('./types').BlogPostSummary[]} * @returns {import('./types').BlogPostSummary[]}
*/ */
export function get_index() { export function get_index() {
return fs return fs
.readdirSync('content/blog') .readdirSync(base)
.reverse() .reverse()
.map((file) => { .map((file) => {
if (!file.endsWith('.md')) return; if (!file.endsWith('.md')) return;
const { date, slug } = get_date_and_slug(file); const { date, slug } = get_date_and_slug(file);
const content = fs.readFileSync(`content/blog/${file}`, 'utf-8'); const content = fs.readFileSync(`${base}/${file}`, 'utf-8');
const { metadata } = extract_frontmatter(content); const { metadata } = extract_frontmatter(content);
return { return {
@ -32,13 +34,13 @@ export function get_index() {
* @returns {import('./types').BlogPost} * @returns {import('./types').BlogPost}
*/ */
export function get_post(slug) { export function get_post(slug) {
for (const file of fs.readdirSync('content/blog')) { for (const file of fs.readdirSync(`${base}`)) {
if (!file.endsWith('.md')) continue; if (!file.endsWith('.md')) continue;
if (file.slice(11, -3) !== slug) continue; if (file.slice(11, -3) !== slug) continue;
const { date, date_formatted } = get_date_and_slug(file); const { date, date_formatted } = get_date_and_slug(file);
const content = fs.readFileSync(`content/blog/${file}`, 'utf-8'); const content = fs.readFileSync(`${base}/${file}`, 'utf-8');
const { metadata, body } = extract_frontmatter(content); const { metadata, body } = extract_frontmatter(content);
return { return {

Loading…
Cancel
Save