{post.metadata.title}
21 |{post.metadata.description}
22 | 23 |{error.message}
14 | 15 | {#if dev && error.stack} 16 |{error.stack}17 | {/if} 18 | 19 | -------------------------------------------------------------------------------- /docs_src/src/routes/_layout.svelte: -------------------------------------------------------------------------------- 1 | 14 | 15 |
This is the 'about' page. There's not much here.
-------------------------------------------------------------------------------- /docs_src/src/routes/api/blog/[slug].js: -------------------------------------------------------------------------------- 1 | import get_posts from './_posts.js'; 2 | 3 | let lookup; 4 | 5 | export function get(req, res) { 6 | if (!lookup) {// || process.env.NODE_ENV !== 'production') { 7 | lookup = new Map(); 8 | get_posts().forEach(post => { 9 | lookup.set(post.slug, JSON.stringify(post)); 10 | }); 11 | } 12 | 13 | if (lookup.has(req.params.slug)) { 14 | res.set({ 15 | 'Content-Type': 'application/json', 16 | 'Cache-Control': `max-age=${5 * 60 * 1e3}` // 5 minutes 17 | }); 18 | res.end(lookup.get(req.params.slug)); 19 | } 20 | } -------------------------------------------------------------------------------- /docs_src/src/routes/api/blog/_posts.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import path from 'path'; 3 | import { extract_frontmatter, langs } from '../../../utils/markdown'; 4 | import marked from 'marked'; 5 | 6 | import PrismJS from 'prismjs'; 7 | import 'prismjs/components/prism-bash'; 8 | 9 | 10 | export default function () { 11 | return fs 12 | .readdirSync('content/blog') 13 | .map(file => { 14 | if (path.extname(file) !== '.md') return; 15 | 16 | const markdown = fs.readFileSync(`content/blog/${file}`, 'utf-8'); 17 | 18 | const { content, metadata } = extract_frontmatter(markdown); 19 | 20 | const date = new Date(`${metadata.pubdate} EDT`); // cheeky hack 21 | metadata.dateString = date.toDateString(); 22 | 23 | const renderer = new marked.Renderer(); 24 | 25 | renderer.code = (source, lang) => { 26 | const plang = langs[lang]; 27 | const highlighted = PrismJS.highlight( 28 | source, 29 | PrismJS.languages[plang], 30 | lang, 31 | ); 32 | 33 | return `${highlighted}
`;
34 | };
35 |
36 | const html = marked(
37 | content.replace(/^\t+/gm, match => match.split('\t').join(' ')),
38 | { renderer }
39 | );
40 |
41 | return {
42 | html,
43 | metadata,
44 | slug: file.replace(/^[\d-]+/, '').replace(/\.md$/, ''),
45 | };
46 | })
47 | .sort((a, b) => a.metadata.pubdate < b.metadata.pubdate ? 1 : -1);
48 | }
49 |
--------------------------------------------------------------------------------
/docs_src/src/routes/api/blog/get.js:
--------------------------------------------------------------------------------
1 | import get_posts from './_posts.js';
2 |
3 | let json;
4 |
5 | export function get(req, res) {
6 | if (!json) { // || process.env.NODE_ENV !== 'production') {
7 | json = JSON.stringify(get_posts().map(post => {
8 | return {
9 | slug: post.slug,
10 | metadata: post.metadata
11 | };
12 | }));
13 | }
14 |
15 | res.set({
16 | 'Content-Type': 'application/json',
17 | 'Cache-Control': `max-age=${5 * 60 * 1e3}` // 5 minutes
18 | });
19 | res.end(json);
20 |
21 | }
--------------------------------------------------------------------------------
/docs_src/src/routes/auth/me.json.js:
--------------------------------------------------------------------------------
1 | export function get(req, res) {
2 | if (!req.session || !req.session.passport || !req.session.passport.user) {
3 | res.send('null');
4 | return;
5 | }
6 |
7 | const { id, username, displayName, photo } = req.session.passport && req.session.passport.user;
8 | res.send({ id, username, displayName, photo });
9 | }
--------------------------------------------------------------------------------
/docs_src/src/routes/blog/index.svelte:
--------------------------------------------------------------------------------
1 |
7 |
8 |
11 |
12 | {post.metadata.description}
22 | 23 |