From 759db36e30dce8794a49d795fd743152039fa9c5 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sat, 20 Apr 2019 09:15:04 -0400 Subject: [PATCH] add mechanism for draft blog posts --- ...016-11-26-frameworks-without-the-framework.md | 1 - .../2017-08-07-the-easiest-way-to-get-started.md | 1 - .../2017-09-06-the-zen-of-just-writing-css.md | 1 - ...sapper-towards-the-ideal-web-app-framework.md | 1 - site/content/blog/2018-04-18-version-2.md | 1 - site/content/blog/2018-12-26-svelte-css-in-js.md | 1 - .../2018-12-27-virtual-dom-is-pure-overhead.md | 1 - .../blog/2019-01-31-svelte-on-the-changelog.md | 1 - .../blog/2019-04-16-svelte-for-new-developers.md | 2 +- site/src/routes/blog/_posts.js | 12 +++++++++--- site/src/routes/blog/index.json.js | 16 ++++++++++------ 11 files changed, 20 insertions(+), 18 deletions(-) diff --git a/site/content/blog/2016-11-26-frameworks-without-the-framework.md b/site/content/blog/2016-11-26-frameworks-without-the-framework.md index 9c663a01ba..933b0fbc48 100644 --- a/site/content/blog/2016-11-26-frameworks-without-the-framework.md +++ b/site/content/blog/2016-11-26-frameworks-without-the-framework.md @@ -1,7 +1,6 @@ --- title: Frameworks without the framework: why didn't we think of this sooner? description: You can't write serious applications in vanilla JavaScript without hitting a complexity wall. But a compiler can do it for you. -pubdate: 2016-11-26 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2017-08-07-the-easiest-way-to-get-started.md b/site/content/blog/2017-08-07-the-easiest-way-to-get-started.md index 4dec8e66fb..b29c3cb5c2 100644 --- a/site/content/blog/2017-08-07-the-easiest-way-to-get-started.md +++ b/site/content/blog/2017-08-07-the-easiest-way-to-get-started.md @@ -1,7 +1,6 @@ --- title: The easiest way to get started with Svelte description: This'll only take a minute. -pubdate: 2017-08-07 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2017-09-06-the-zen-of-just-writing-css.md b/site/content/blog/2017-09-06-the-zen-of-just-writing-css.md index c89935c104..4ea56bc633 100644 --- a/site/content/blog/2017-09-06-the-zen-of-just-writing-css.md +++ b/site/content/blog/2017-09-06-the-zen-of-just-writing-css.md @@ -1,7 +1,6 @@ --- title: The zen of Just Writing CSS description: I would say this is the future, but we're already doing it. -pubdate: 2017-09-06 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2017-12-31-sapper-towards-the-ideal-web-app-framework.md b/site/content/blog/2017-12-31-sapper-towards-the-ideal-web-app-framework.md index 614f266136..ff986a2258 100644 --- a/site/content/blog/2017-12-31-sapper-towards-the-ideal-web-app-framework.md +++ b/site/content/blog/2017-12-31-sapper-towards-the-ideal-web-app-framework.md @@ -1,7 +1,6 @@ --- title: Sapper: Towards the ideal web app framework description: Taking the next-plus-one step -pubdate: 2017-12-31 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2018-04-18-version-2.md b/site/content/blog/2018-04-18-version-2.md index 295efbbd11..7e5441f090 100644 --- a/site/content/blog/2018-04-18-version-2.md +++ b/site/content/blog/2018-04-18-version-2.md @@ -1,7 +1,6 @@ --- title: Svelte v2 is out! description: Here's what you need to know -pubdate: 2018-04-18 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2018-12-26-svelte-css-in-js.md b/site/content/blog/2018-12-26-svelte-css-in-js.md index 40bbfe8bd1..dccfcb4a17 100644 --- a/site/content/blog/2018-12-26-svelte-css-in-js.md +++ b/site/content/blog/2018-12-26-svelte-css-in-js.md @@ -1,7 +1,6 @@ --- title: Using CSS-in-JS with Svelte description: You don't need to, but you can -pubdate: 2018-12-26 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2018-12-27-virtual-dom-is-pure-overhead.md b/site/content/blog/2018-12-27-virtual-dom-is-pure-overhead.md index f70bda43d5..d71652fe8d 100644 --- a/site/content/blog/2018-12-27-virtual-dom-is-pure-overhead.md +++ b/site/content/blog/2018-12-27-virtual-dom-is-pure-overhead.md @@ -1,7 +1,6 @@ --- title: Virtual DOM is pure overhead description: Let's retire the 'virtual DOM is fast' myth once and for all -pubdate: 2018-12-27 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2019-01-31-svelte-on-the-changelog.md b/site/content/blog/2019-01-31-svelte-on-the-changelog.md index 79ad985bf9..936c50240e 100644 --- a/site/content/blog/2019-01-31-svelte-on-the-changelog.md +++ b/site/content/blog/2019-01-31-svelte-on-the-changelog.md @@ -1,7 +1,6 @@ --- title: Svelte on The Changelog description: Listen to the interview here -pubdate: 2019-01-31 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2019-04-16-svelte-for-new-developers.md b/site/content/blog/2019-04-16-svelte-for-new-developers.md index f7700bf4d3..9018de14a2 100644 --- a/site/content/blog/2019-04-16-svelte-for-new-developers.md +++ b/site/content/blog/2019-04-16-svelte-for-new-developers.md @@ -1,9 +1,9 @@ --- title: Svelte for new developers description: Never used Node.js or the command line? No problem -pubdate: 2019-04-16 author: Rich Harris authorURL: https://twitter.com/Rich_Harris +draft: true --- TODO walk through installing Node.js and git and using Terminal.app (or whatever the Windows equivalent is) to clone a project template and start developing \ No newline at end of file diff --git a/site/src/routes/blog/_posts.js b/site/src/routes/blog/_posts.js index fc2bed469a..7a99011c95 100644 --- a/site/src/routes/blog/_posts.js +++ b/site/src/routes/blog/_posts.js @@ -5,17 +5,23 @@ import marked from 'marked'; import PrismJS from 'prismjs'; import 'prismjs/components/prism-bash'; -export default function() { +export default function get_posts() { return fs .readdirSync('content/blog') .map(file => { if (path.extname(file) !== '.md') return; + const match = /^(\d+-\d+-\d+)-(.+)\.md$/.exec(file); + if (!match) throw new Error(`Invalid filename '${file}'`); + + const [, pubdate, slug] = match; + const markdown = fs.readFileSync(`content/blog/${file}`, 'utf-8'); const { content, metadata } = extract_frontmatter(markdown); - const date = new Date(`${metadata.pubdate} EDT`); // cheeky hack + const date = new Date(`${pubdate} EDT`); // cheeky hack + metadata.pubdate = pubdate; metadata.dateString = date.toDateString(); const renderer = new marked.Renderer(); @@ -41,7 +47,7 @@ export default function() { return { html, metadata, - slug: file.replace(/^[\d-]+/, '').replace(/\.md$/, ''), + slug }; }) .sort((a, b) => a.metadata.pubdate < b.metadata.pubdate ? 1 : -1); diff --git a/site/src/routes/blog/index.json.js b/site/src/routes/blog/index.json.js index ed5076c95c..b2609505a4 100644 --- a/site/src/routes/blog/index.json.js +++ b/site/src/routes/blog/index.json.js @@ -4,12 +4,16 @@ let json; export function get(req, res) { if (!json || process.env.NODE_ENV !== 'production') { - json = JSON.stringify(get_posts().map(post => { - return { - slug: post.slug, - metadata: post.metadata - }; - })); + const posts = get_posts() + .filter(post => !post.metadata.draft) + .map(post => { + return { + slug: post.slug, + metadata: post.metadata + }; + }); + + json = JSON.stringify(posts); } res.set({