parent
a799f3cb2e
commit
d8725b6e22
@ -0,0 +1,51 @@
|
||||
const fs = require('fs').promises;
|
||||
const {promisify} = require('util');
|
||||
const frontMatterParser = require('parser-front-matter');
|
||||
|
||||
const parse = promisify(frontMatterParser.parse.bind(frontMatterParser));
|
||||
|
||||
async function loadPostsWithFrontMatter(postsDirectoryPath) {
|
||||
const postNames = await fs.readdir(postsDirectoryPath);
|
||||
const posts = await Promise.all(
|
||||
postNames.map(async fileName => {
|
||||
const fileContent = await fs.readFile(
|
||||
`${postsDirectoryPath}/${fileName}`,
|
||||
'utf8'
|
||||
);
|
||||
const {content, data} = await parse(fileContent);
|
||||
return {
|
||||
content: content.slice(0, 3000),
|
||||
...data
|
||||
};
|
||||
})
|
||||
);
|
||||
return posts;
|
||||
}
|
||||
|
||||
const lunrjs = require('lunr');
|
||||
|
||||
function makeIndex(posts) {
|
||||
return lunrjs(function() {
|
||||
this.ref('title');
|
||||
this.field('title');
|
||||
this.field('content');
|
||||
this.field('tags');
|
||||
posts.forEach(p => {
|
||||
this.add(p);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const posts = await loadPostsWithFrontMatter(`${__dirname}/content/post`);
|
||||
const leren = await loadPostsWithFrontMatter(`${__dirname}/content/leren`);
|
||||
const index = makeIndex(posts.concat(leren));
|
||||
console.log(JSON.stringify(index));
|
||||
}
|
||||
|
||||
run()
|
||||
.then(() => process.exit(0))
|
||||
.catch(error => {
|
||||
console.error(error.stack);
|
||||
process.exit(1);
|
||||
});
|
@ -1,5 +1,7 @@
|
||||
---
|
||||
title: Over
|
||||
aliases:
|
||||
- /about/
|
||||
date: 2012-12-06T16:29:31+00:00
|
||||
---
|
||||
|
@ -0,0 +1,11 @@
|
||||
---
|
||||
title: Zoeken
|
||||
aliases:
|
||||
- /search
|
||||
---
|
||||
|
||||
# Zoeken
|
||||
|
||||
> Niet gevonden wat je zocht? Probeer je geluk hier:
|
||||
|
||||
{{< searchbox >}}
|
@ -0,0 +1,27 @@
|
||||
<form method="get" action="">
|
||||
<input id="zoekentxt" placeholder="zuurdesembrood" name="q" type="text" style="width: 50%" />
|
||||
<button type="submit" class="button">Zoeken</button>
|
||||
<a href="/zoeken">Leegmaken</a>
|
||||
</form>
|
||||
|
||||
<div id="resultaten">
|
||||
<hr/>
|
||||
<h1>
|
||||
Zoekresultaten
|
||||
<span class="pages"></span> »
|
||||
</h1>
|
||||
<div id="searchapp"></div>
|
||||
</div>
|
||||
|
||||
<script src="https://unpkg.com/lunr/lunr.js"></script>
|
||||
<!-- Generate a list of posts so we can display them -->
|
||||
{{ $p := slice }}
|
||||
{{ range .Site.RegularPages }}
|
||||
{{ $post := dict "link" .RelPermalink "title" .Title "content" (substr .Plain 0 200) -}}
|
||||
{{ $p = $p | append $post -}}
|
||||
{{ end }}
|
||||
<script>
|
||||
window.searchposts = JSON.parse(
|
||||
{{ $p | jsonify }}
|
||||
);
|
||||
</script>
|
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
{"Target":"css/styles.a824af1bdd031310f727c3e894c744b9fec7a5b5d06083cb4772632588eea8ea8c4c7030050086a2243a46b54dbb3e84236a766ce1776e05683a6e166e1fcf9f.css","MediaType":"text/css","Data":{"Integrity":"sha512-qCSvG90DExD3J8PolMdEuf7HpbXQYIPLR3JjJYjuqOqMTHAwBQCGoiQ6RrVNuz6EI2p2bOF3bgVoOm4Wbh/Pnw=="}}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue