diff --git a/README.md b/README.md index 6ce3c5e..6997de1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ # revival-archive Revival archive website + +# Pages/posts + +To make a post, place it into the /pages directory. The filename will be used as the URL slug. The file must be in Markdown and contain a json header, like the following: + +```json +{ + "title": "First blog post", + "date": "2023-07-06 7:29 PM" +} +``` diff --git a/pages/blog/first.md b/pages/blog/first.md index 9e7c611..ef153da 100644 --- a/pages/blog/first.md +++ b/pages/blog/first.md @@ -1,5 +1,9 @@ -First blog post -2023-06-07 +```json +{ + "title": "First blog post", + "date": "2023-07-06 7:29 PM" +} +``` I'm baby portland cred tote bag ethical glossier etsy fixie edison bulb retro irony. Helvetica beard humblebrag before they sold out photo booth yr cloud bread iceland ennui yes plz cold-pressed solarpunk tacos marxism. Yr occupy squid pug helvetica crucifix enamel pin subway tile bruh jean shorts fanny pack. Meditation gluten-free butcher PBR&B twee. Hammock selfies asymmetrical fixie before they sold out. diff --git a/pages/blog/second.md b/pages/blog/second.md index 3155d8a..99bee00 100644 --- a/pages/blog/second.md +++ b/pages/blog/second.md @@ -1,14 +1,18 @@ -Second blog post -2023-06-07 +```json +{ + "title": "Second blog post", + "date": "2023-07-09 11:40 AM" +} +``` -I'm baby portland cred tote bag ethical glossier etsy fixie edison bulb retro irony. Helvetica beard humblebrag before they sold out photo booth yr cloud bread iceland ennui yes plz cold-pressed solarpunk tacos marxism. Yr occupy squid pug helvetica crucifix enamel pin subway tile bruh jean shorts fanny pack. Meditation gluten-free butcher PBR&B twee. Hammock selfies asymmetrical fixie before they sold out. +Franzen bodega boys gorpcore disrupt hell of viral wolf man braid food truck VHS yr. Gentrify tumblr meditation, art party try-hard vaporware direct trade echo park helvetica you probably haven't heard of them disrupt fam. Poutine portland gatekeep bespoke. Organic neutra jianbing, occupy distillery 3 wolf moon big mood bitters tumblr actually forage tattooed. DIY messenger bag listicle, sustainable bitters sus portland. Gentrify VHS freegan artisan solarpunk seitan bruh hoodie live-edge drinking vinegar vape iceland palo santo +1. -Grailed iceland austin chicharrones sriracha 8-bit praxis kinfolk blog everyday carry trust fund DIY pour-over. Sriracha disrupt PBR&B fam gorpcore bodega boys adaptogen butcher. Master cleanse tumeric slow-carb activated charcoal jean shorts freegan artisan poke trust fund poutine paleo marxism viral sartorial. Wayfarers neutral milk hotel unicorn art party skateboard. Actually williamsburg chicharrones palo santo direct trade seitan kickstarter humblebrag church-key air plant tacos sriracha. Vape blackbird spyplane kickstarter +1 hexagon PBR&B. Organic copper mug aesthetic, XOXO marxism quinoa subway tile irony lumbersexual authentic disrupt kitsch solarpunk. +Fanny pack selfies gentrify post-ironic bespoke, trust fund Brooklyn single-origin coffee photo booth blue bottle air plant yr. Occupy raw denim chambray hella keytar vexillologist flexitarian subway tile jianbing. Fanny pack selfies pour-over irony quinoa echo park JOMO jawn tumeric. Cardigan tumeric squid thundercats microdosing. Pitchfork pork belly irony aesthetic offal shoreditch. Fit narwhal everyday carry shabby chic. Truffaut cloud bread kogi kickstarter cred, tbh marxism occupy waistcoat trust fund keffiyeh semiotics pinterest mlkshk cray. -Whatever JOMO organic artisan photo booth marfa, wayfarers yes plz cray. Keffiyeh gentrify thundercats affogato small batch retro you probably haven't heard of them drinking vinegar try-hard vibecession enamel pin. Tbh crucifix seitan, ennui jawn vice lo-fi DSA franzen fingerstache chillwave vape. Sartorial subway tile forage vaporware organic, XOXO letterpress. +Mixtape big mood franzen 90's. Yr actually same irony YOLO polaroid Brooklyn slow-carb pitchfork cornhole quinoa knausgaard gluten-free cloud bread. Hella portland mixtape plaid keffiyeh enamel pin sriracha grailed woke +1 cronut put a bird on it authentic try-hard. Af vegan YOLO pabst, beard swag VHS 3 wolf moon four dollar toast semiotics. -Mustache bicycle rights copper mug pitchfork af typewriter. Vinyl copper mug bitters sus brunch. Biodiesel copper mug vexillologist, butcher asymmetrical seitan man bun everyday carry. Cray humblebrag lumbersexual Brooklyn chambray vice. Taxidermy viral keytar XOXO hell of intelligentsia next level. +Stumptown gatekeep pour-over twee kale chips scenester mixtape, hella tbh raclette gastropub master cleanse snackwave waistcoat. Lyft aesthetic hella neutra cronut, green juice cliche banh mi mukbang. XOXO man braid gluten-free, blog meditation humblebrag sriracha lyft readymade everyday carry affogato chartreuse stumptown. Thundercats air plant messenger bag skateboard cold-pressed organic. Hoodie letterpress 8-bit vegan. -Squid polaroid cold-pressed bitters, tousled enamel pin succulents. Seitan semiotics tumblr shabby chic heirloom salvia, beard gorpcore narwhal williamsburg forage. Austin synth locavore XOXO succulents artisan. Bodega boys bespoke bicycle rights shaman, mukbang leggings selvage irony yuccie polaroid kale chips activated charcoal chambray. Deep v migas pour-over edison bulb tilde chia vinyl, letterpress umami wolf hot chicken franzen taxidermy health goth tonx. Post-ironic gastropub heirloom, plaid literally dreamcatcher pop-up YOLO migas shoreditch brunch. Lo-fi glossier single-origin coffee, tattooed vegan hexagon kinfolk actually YOLO prism. +Pitchfork cloud bread umami fam. Everyday carry subway tile cronut celiac air plant hoodie. Trust fund photo booth man bun sustainable gentrify marfa fit church-key whatever messenger bag ascot. Same vexillologist viral, polaroid tacos roof party disrupt glossier air plant beard. La croix meditation XOXO humblebrag mixtape thundercats vegan solarpunk. Dummy text? More like dummy thicc text, amirite? diff --git a/pages/pages.js b/pages/pages.js index a03851b..f75c027 100644 --- a/pages/pages.js +++ b/pages/pages.js @@ -23,26 +23,23 @@ function walk(dir) { const allMdFiles = walk("./pages") -fs.rmSync("./pagesjson", { recursive: true }) +if (fs.existsSync("./pagesjson")) fs.rmSync("./pagesjson", { recursive: true }) allMdFiles.forEach(file => { let md = fs.readFileSync(file.name, "utf8") - const lines = md.split("\n") + // Get json data from the top of the file + const [json, content] = md + .match(/^```json[\s\S]*({[\s\S]+})[\s\S]*```\n*([\s\S]+)$/) + .slice(1, 3) - // Remove the first line of the file - const title = lines.shift() - const date = new Date(lines.shift()) - lines.shift() // Remove the empty line - - md = lines.join("\n") - - const html = marked.parse(md, { - mangle: false, - headerIds: false, - }) - - const obj = { title, date, html } + const obj = { + ...JSON.parse(json), + html: marked.parse(content, { + mangle: false, + headerIds: false, + }), + } fs.mkdirSync( file.name diff --git a/src/routes/blog/[page]/+page.server.ts b/src/routes/blog/[page]/+page.server.ts index 65a9afb..50016da 100644 --- a/src/routes/blog/[page]/+page.server.ts +++ b/src/routes/blog/[page]/+page.server.ts @@ -1,16 +1,27 @@ import { error } from "@sveltejs/kit" +import { load as loadParent } from "../+page" export async function load({ params }) { + let title: string, date: Date, html: string + try { - const { title, date, html } = await import( + ;({ title, date, html } = await import( `../../../../pagesjson/blog/${params.page}.json` - ) - return { - html, - title, - date, - } + )) } catch (e) { throw error(404, "Post not found") } + + const posts = await (await loadParent()).posts + + // remove the current post from the list + const index = posts.findIndex(post => post.title == title) + posts.splice(index, 1) + + return { + title, + date, + html, + posts, + } } diff --git a/src/routes/blog/[page]/+page.svelte b/src/routes/blog/[page]/+page.svelte index dc8f773..7b2d49f 100644 --- a/src/routes/blog/[page]/+page.svelte +++ b/src/routes/blog/[page]/+page.svelte @@ -1,28 +1,63 @@ + {data.title} • Revival Archive -
- -

{data.title}

- - Published {new Date(data.date).toLocaleDateString("en-GB", { - year: "numeric", - month: "long", - day: "numeric", - hour: "numeric", - minute: "numeric", - })} - -
+
+
+
+ ← Back to blog +
+ +

{data.title}

+ + Published {when(data.date)} + +
-
+
-
- {@html data.html} -
-
+
+ {@html data.html} +
+
+ +
+ {#if data.posts.length > 0} +
+

Other posts

+ {#each data.posts as post} + +
+

{post.title}

+ + Published {when(post.date)} + +
+
+ {/each} +
+ {/if} + + +