MCPcopy Create free account
hub / github.com/electric-sql/electric / load

Function load

website/data/posts.data.ts:13–47  ·  view source on GitHub ↗
(files: string[])

Source from the content-addressed store, hash-verified

11 watch: [`../blog/posts/*.md`],
12
13 load(files: string[]) {
14 return files
15 .map((file) => {
16 const base = path.basename(file, `.md`)
17 const parts = base.split(`-`)
18
19 const year = parts[0]
20 const month = parts[1]
21 const day = parts[2]
22 const slug = parts.slice(3, 99).join(`-`)
23
24 const contents = fs.readFileSync(file, `utf-8`)
25 const frontmatter = contents.split(`---\n`)[1]
26
27 const parsed = parsePostFrontmatter(frontmatter)
28 const excerpt = typeof parsed.excerpt === `string` ? parsed.excerpt : ``
29 const bodyExcerpt = contents
30 .split(`---\n`)[2]
31 .split(`<!--truncate-->`)[0]
32 .trim()
33 const resolvedExcerpt = excerpt || bodyExcerpt
34
35 const date = `${year}-${month}-${day}`
36 const blogPath = `/blog/${year}/${month}/${day}/${slug}`
37
38 return {
39 ...parsed,
40 date,
41 path: blogPath,
42 excerpt: resolvedExcerpt,
43 } satisfies PostListRow
44 })
45 .filter((row) => row.published !== false)
46 .sort((a, b) => (a.path < b.path ? 1 : -1))
47 },
48}

Callers

nothing calls this directly

Calls 5

parsePostFrontmatterFunction · 0.85
filterMethod · 0.80
mapMethod · 0.45
joinMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected