forked from javascript-tutorial/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.js
More file actions
executable file
·67 lines (50 loc) · 1.41 KB
/
Copy pathtask.js
File metadata and controls
executable file
·67 lines (50 loc) · 1.41 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
62
63
64
65
66
"use strict";
const mongoose = require('mongoose');
const Task = require('../models/task');
const Article = require('../models/article');
const TaskRenderer = require('../renderer/taskRenderer');
exports.get = function *get(next) {
const task = yield Task.findOne({
slug: this.params.slug
}).populate('parent');
if (!task) {
yield* next;
return;
}
const renderer = new TaskRenderer();
const rendered = yield* renderer.renderWithCache(task);
this.locals.githubLink = task.githubLink;
var breadcrumbs = [];
var parentId = task.parent._id;
while (true) {
let parent = yield Article.findById(parentId, {slug: 1, title: 1, parent: 1}).exec();
if (!parent) break;
breadcrumbs.push({
url: parent.getUrl(),
title: parent.title
});
parentId = parent.parent;
}
breadcrumbs.push({
title: 'Учебник',
url: '/'
});
/*
breadcrumbs.push({
title: 'JavaScript.ru',
url: 'http://javascript.ru'
});
*/
this.locals.breadcrumbs = breadcrumbs.reverse();
this.locals.siteToolbarCurrentSection = "tutorial";
// No support for task.libs & head just yet (not needed?)
this.locals.title = task.title;
this.locals.task = {
title: task.title,
importance: task.importance,
content: rendered.content,
solution: rendered.solution
};
this.locals.articleUrl = task.parent.getUrl();
this.body = this.render("task");
};