Skip to content

Commit 96db9eb

Browse files
committed
update context templates
1 parent 98e827d commit 96db9eb

10 files changed

+37
-20
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ npx live-server --port=1234
1010
deno run --allow-read --allow-write scripts/new-document.ts --date=YYYY/MM/DD
1111

1212
# make a new piece of context
13-
deno run --allow-read --allow-write scripts/new-context.ts --date=YYYY/MM/DD
13+
deno run --allow-read --allow-write scripts/new-context.ts --date=YYYY/MM/DD --type=article
1414

1515
# build root index.html
1616
deno run --allow-read --allow-write scripts/build-index.ts

scripts/build-index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Entry = {
88
date: string
99
}
1010

11-
// this is a subset of what the new-context-template.yml contains
11+
// this is a subset of what the new-context.yml contains
1212
type Context = {
1313
title: string
1414
original_url: string
@@ -72,8 +72,8 @@ context.sort((a, b) => {
7272
return a[0] > b[0] ? -1 : 1
7373
})
7474

75-
const document = new DOMParser().parseFromString(await Deno.readTextFile("./scripts/index-document-template.html"), "text/html")
76-
const contextDocument = new DOMParser().parseFromString(await Deno.readTextFile("./scripts/context-document-template.html"), "text/html")
75+
const document = new DOMParser().parseFromString(await Deno.readTextFile("./scripts/templates/index-document.html"), "text/html")
76+
const contextDocument = new DOMParser().parseFromString(await Deno.readTextFile("./scripts/templates/context-document.html"), "text/html")
7777

7878
if (!document || !contextDocument) {
7979
throw new Error('Could not create document')

scripts/new-context-template.yml

-10
This file was deleted.

scripts/new-context.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
import { parseArgs } from "https://deno.land/[email protected]/cli/parse_args.ts";
22
import { validateDate } from "./common.ts";
33

4+
const validTypes = ["article", "podcast"]
5+
46
const flags = parseArgs(Deno.args, {
5-
string: ["date"],
7+
string: ["date", "type"],
68
});
79

8-
if (!flags.date) {
9-
throw new Error("Missing date flag")
10+
if (!flags.date || !flags.type) {
11+
throw new Error("Missing date or type flag")
1012
}
1113

1214
validateDate(flags.date)
1315

16+
if (!validTypes.includes(flags.type)) {
17+
throw new Error(`Invalid type: ${flags.type}`)
18+
}
19+
1420
const id = Math.floor(Date.now() / 1000)
1521
const path = `./${flags.date}/context`
1622
const filePath = `${path}/${id}.yml`
1723

1824
// create path
1925
await Deno.mkdir(path, { recursive: true })
2026
// load template
21-
const template = await Deno.readTextFile("./scripts/new-context-template.yml")
27+
const template = await Deno.readTextFile(`./scripts/templates/${flags.type}.yml`)
2228
// write file to path
2329
await Deno.writeTextFile(filePath, template)
24-
console.log(`🎉 Created new context ${flags.date}`)
30+
console.log(`🎉 Created new ${flags.type} context ${flags.date}`)
2531

scripts/new-document.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ try {
2020
console.log(`🚨 ${flags.date} already exists`)
2121
} catch {
2222
await Deno.mkdir(path, { recursive: true })
23-
const template = await Deno.readTextFile("./scripts/new-document-template.html")
23+
const template = await Deno.readTextFile("./scripts/templates/new-document.html")
2424
await Deno.writeTextFile(filePath, template)
2525
console.log(`🎉 Created ${flags.date}`)
2626
}

scripts/templates/article.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type: article
2+
language: english | dutch | german | swiss-german
3+
author: null
4+
date: YYYY-MM-DD
5+
title: null
6+
website: null
7+
url: null
8+
private_url: null
9+
notes: null
File renamed without changes.
File renamed without changes.
File renamed without changes.

scripts/templates/podcast.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
type: podcast
2+
language: english | dutch | german | swiss-german
3+
host: null
4+
episode_title: null
5+
podcast_name: null
6+
season_number: null
7+
episode_number: null
8+
publisher: null
9+
day_month_year: YYYY-MM-DD
10+
url: null
11+
private_url: null
12+
notes: null

0 commit comments

Comments
 (0)