generated from open-innovations/oi-lume-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_config.ts
95 lines (78 loc) · 2.89 KB
/
_config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import lume from "lume/mod.ts";
import nunjucks from "lume/plugins/nunjucks.ts"; // Lume 2.0 requires us to add Nunjucks
import base_path from "lume/plugins/base_path.ts";
import date from "lume/plugins/date.ts";
import metas from "lume/plugins/metas.ts";
import postcss from "lume/plugins/postcss.ts";
import { walkSync } from 'std/fs/mod.ts';
import sitemap from "lume/plugins/sitemap.ts"; // To build a site map
// Importing the OI Lume charts and utilities
import oiViz from "https://deno.land/x/[email protected]/mod.ts";
import autoDependency from "https://deno.land/x/[email protected]/processors/auto-dependency.ts";
import csvLoader from "https://deno.land/x/[email protected]/loaders/csv-loader.ts";
import jsonLoader from "lume/core/loaders/json.ts";
const site = lume({
src: './src',
// TODO Update this with the proper URL
location: new URL("https://constituencies.open-innovations.org/"),
});
site.use(nunjucks());
site.use(sitemap({
query: "!draft"
}));
// Register a series of extensions to be loaded by the OI CSV loader
// https://lume.land/docs/core/loaders/
site.loadData([".csv", ".tsv", ".dat"], csvLoader({ basic: true }));
site.loadData([".geojson"], jsonLoader);
site.loadData([".hexjson"], jsonLoader);
/**
* Descend into a folder tree and remotely map each file to the Lume build
*
* @param {string} source Source directory, relative to this file
* @param {string} target Location in the lume build virtual file system
*/
function remoteTree(source, target) {
const files = Array.from(walkSync(source, {
includeDirs: false,
})).map(({ path }) => path);
files.forEach(remote => {
const local = remote.replace(source, target);
site.remoteFile(local, './' + remote);
});
}
const dataPath = '/data';
// Mirror source data files to live site
remoteTree('src/_data/sources', dataPath);
// Copy /data to live site
site.copy(dataPath);
// Mirror source data files to live site
remoteTree('src/_data/hexjson', '/assets/hexjson/');
// Copy /data to live site
site.copy('/assets/hexjson/');
site.copy([".png"]);
// Register an HTML processor
// https://lume.land/docs/core/processors/
site.process([".html"], (pages) => pages.forEach(autoDependency));
site.loadAssets([".css"]);
site.loadAssets([".js"]);
//site.loadAssets([".svg"]);
site.loadAssets([".hexjson"]);
// Import lume viz
import oiVizConfig from "./oi-viz-config.ts";
site.use(oiViz(oiVizConfig));
// Add filters
site.filter('match', (value, regex) => { const re = new RegExp(regex); return value.match(re); });
site.filter('keys', o => Object.keys(o) );
site.use(metas({
defaultPageData: {
title: 'title', // Use the `date` value as fallback.
},
}));
site.use(date());
site.use(postcss({}));
// This should normally run late on, as it registers a processor which re-writes URLs.
// These could be updated by prior processors.
site.use(base_path());
site.copy('CNAME');
site.copy('.nojekyll');
export default site;