Skip to content

Commit fd8355d

Browse files
committed
start preprint
add page word count to paper/+layout.svelte
1 parent 1ae72c0 commit fd8355d

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

site/src/app.css

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ pre {
9090
ul {
9191
padding-left: 1em;
9292
}
93+
:is(ul, ol) > li > p {
94+
margin: 1ex 0;
95+
}
9396
label {
9497
cursor: pointer;
9598
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import fs from 'fs'
2+
import type { LayoutServerLoad } from './$types'
3+
4+
export const load: LayoutServerLoad = async ({ route }) => {
5+
const data = fs.readFileSync(`src/routes/${route.id}/+page.md`, `utf8`)
6+
7+
// Count the number of words using a regular expression
8+
const word_count = data.match(/\b\w+\b/g)?.length ?? null
9+
10+
return { word_count }
11+
}

site/src/routes/paper/+layout.svelte

+10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<script lang="ts">
22
import { References } from '$lib'
3+
import { pretty_num } from 'elementari/labels'
4+
import type { LayoutServerData } from './$types'
35
import { affiliations, authors, date, subtitle, title } from './frontmatter.yml'
46
import { references } from './references.yaml'
7+
8+
export let data: LayoutServerData
59
</script>
610

711
<h1>{title}<br /><small>{subtitle}</small></h1>
@@ -26,6 +30,12 @@
2630

2731
<References {references} />
2832

33+
<small style="float: right;">
34+
<code>{pretty_num(data.word_count)}</code> words (<code>
35+
~{Math.floor(data.word_count / 200)}</code
36+
> min)
37+
</small>
38+
2939
<style>
3040
address {
3141
text-align: center;

0 commit comments

Comments
 (0)