Skip to content

Commit

Permalink
start preprint
Browse files Browse the repository at this point in the history
add page word count to paper/+layout.svelte
  • Loading branch information
janosh committed Jun 20, 2023
1 parent 1ae72c0 commit fd8355d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions site/src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ pre {
ul {
padding-left: 1em;
}
:is(ul, ol) > li > p {
margin: 1ex 0;
}
label {
cursor: pointer;
}
Expand Down
11 changes: 11 additions & 0 deletions site/src/routes/paper/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import fs from 'fs'
import type { LayoutServerLoad } from './$types'

export const load: LayoutServerLoad = async ({ route }) => {
const data = fs.readFileSync(`src/routes/${route.id}/+page.md`, `utf8`)

// Count the number of words using a regular expression
const word_count = data.match(/\b\w+\b/g)?.length ?? null

return { word_count }
}
10 changes: 10 additions & 0 deletions site/src/routes/paper/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts">
import { References } from '$lib'
import { pretty_num } from 'elementari/labels'
import type { LayoutServerData } from './$types'
import { affiliations, authors, date, subtitle, title } from './frontmatter.yml'
import { references } from './references.yaml'
export let data: LayoutServerData
</script>

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

<References {references} />

<small style="float: right;">
<code>{pretty_num(data.word_count)}</code> words (<code>
~{Math.floor(data.word_count / 200)}</code
> min)
</small>

<style>
address {
text-align: center;
Expand Down

0 comments on commit fd8355d

Please sign in to comment.