-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathfrontpage.js
More file actions
executable file
·61 lines (43 loc) · 1.39 KB
/
Copy pathfrontpage.js
File metadata and controls
executable file
·61 lines (43 loc) · 1.39 KB
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
const Article = require('engine/koa/tutorial').Article;
const TutorialTree = require('engine/koa/tutorial').TutorialTree;
const Task = require('engine/koa/tutorial').Task;
const _ = require('lodash');
const ArticleRenderer = require('engine/koa/tutorial').ArticleRenderer;
const localStorage = require('engine/local-storage').instance();
const t = require('engine/i18n');
t.requirePhrase('frontpage');
exports.get = async function (ctx, next) {
ctx.locals.sitetoolbar = true;
ctx.locals.siteToolbarCurrentSection = "tutorial";
ctx.locals.title = t('frontpage.modern_javascript_tutorial');
let topArticlesRendered = await localStorage.getOrGenerate('frontpage', renderTop, process.env.TUTORIAL_EDIT);
if (!Object.keys(topArticlesRendered).length) {
ctx.throw(404, "Database is empty?"); // empty db
}
let locals = {
tutorialTree: TutorialTree.instance(),
topArticlesRendered
};
ctx.body = ctx.render('frontpage', locals);
};
// content
// metadata
// modified
// title
// isFolder
// prev
// next
// path
// siblings
async function renderTop() {
const roots = TutorialTree.instance().roots;
let articles = {};
// render top-level content
for (let slug of roots) {
let article = TutorialTree.instance().bySlug(slug);
let renderer = new ArticleRenderer();
let rendered = await renderer.render(article);
articles[slug] = rendered;
}
return articles;
}