Skip to content

Commit e79cd83

Browse files
committed
WIP
1 parent b64b379 commit e79cd83

File tree

34 files changed

+133
-541
lines changed

34 files changed

+133
-541
lines changed

cache/tutorialTree.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

cache/tutorialViewStorage.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

cache/webpack.versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"footer":"/pack/footer.js?8a8b5e8833c3f1ff8dc7","head":"/pack/head.js?8a8b5e8833c3f1ff8dc7","styles":["/pack/styles.js?8a8b5e8833c3f1ff8dc7","/pack/styles.css?7cad2a83ed59a4a872b6c00b58c0bc02"],"tutorial":"/pack/tutorial.js?8a8b5e8833c3f1ff8dc7"}
1+
{"footer":"/pack/footer.js?ac0d9ec6312de889f54c","head":"/pack/head.js?ac0d9ec6312de889f54c","styles":["/pack/styles.js?ac0d9ec6312de889f54c","/pack/styles.css?cb58fe2ae21d9517d8f37e774560d011"],"tutorial":"/pack/tutorial.js?ac0d9ec6312de889f54c"}

handlers/tutorial/controller/frontpage.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,25 @@ const LANG = require('config').lang;
1212

1313
t.requirePhrase('tutorial.frontpage', require('../locales/frontpage/' + LANG + '.yml'));
1414

15+
1516
exports.get = async function (ctx, next) {
1617

1718
ctx.locals.sitetoolbar = true;
1819
ctx.locals.siteToolbarCurrentSection = "tutorial";
1920
ctx.locals.title = t('tutorial.frontpage.modern_javascript_tutorial');
2021

21-
let topArticles = await localStorage.getOrGenerate('tutorial:frontpage', renderTop);
22+
let topArticlesRendered = await localStorage.getOrGenerate('tutorial:frontpage', renderTop);
2223

23-
if (!topArticles.length) {
24+
if (!Object.keys(topArticlesRendered).length) {
2425
ctx.throw(404, "Database is empty?"); // empty db
2526
}
2627

27-
let chapters = data.contents.slice(0, 2).concat({
28-
title: "Additional articles",
29-
content: "List of extra topics that are not covered by first two parts of tutorial. There is no clear hierarchy here, you can access articles in the order you want.",
30-
children: data.contents.slice(2)
31-
});
28+
3229
let locals = {
33-
chapters: TutorialTree.instance().tree,
34-
topArticles
30+
tutorialTree: TutorialTree.instance(),
31+
topArticlesRendered
3532
};
3633

37-
38-
console.log(locals);
39-
4034
ctx.body = ctx.render('frontpage', locals);
4135
};
4236

@@ -52,7 +46,7 @@ exports.get = async function (ctx, next) {
5246
async function renderTop() {
5347
const tree = TutorialTree.instance().tree;
5448

55-
let articles = [];
49+
let articles = {};
5650

5751
// render top-level content
5852
for (let slug of tree) {
@@ -61,7 +55,8 @@ async function renderTop() {
6155
let renderer = new ArticleRenderer();
6256

6357
let rendered = await renderer.render(article);
64-
articles.push(rendered);
58+
59+
articles[slug] = rendered;
6560
}
6661

6762

handlers/tutorial/lib/tutorialImporter.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ module.exports = class TutorialImporter {
3535
this.tree = TutorialTree.instance();
3636
}
3737

38-
async sync(directory) {
38+
/*
39+
update=false => removes old entry and re-imports
40+
update=true => doesnn't remove anything, for adding only (checks for dupe slugs)
41+
*/
42+
async sync(directory, update = false) {
3943

4044
log.info("sync", directory);
4145
let dir = fs.realpathSync(directory);
@@ -71,6 +75,10 @@ module.exports = class TutorialImporter {
7175
parentSlug = parentSlug.slice(parentSlug.indexOf('-') + 1);
7276

7377
let parent = this.tree.bySlug(parentSlug);
78+
79+
if (update) {
80+
this.tree.destroyTree(parentSlug);
81+
}
7482
await this['sync' + type](dir, parent);
7583

7684
}
@@ -102,7 +110,7 @@ module.exports = class TutorialImporter {
102110
data.weight = parseInt(folderFileName);
103111
data.slug = folderFileName.slice(folderFileName.indexOf('-') + 1);
104112

105-
this.tree.destroyTree(data.slug);
113+
//this.tree.destroyTree(data.slug);
106114

107115
let options = {
108116
staticHost: config.server.staticHost,
@@ -173,7 +181,7 @@ module.exports = class TutorialImporter {
173181
data.weight = parseInt(articlePathName);
174182
data.slug = articlePathName.slice(articlePathName.indexOf('-') + 1);
175183

176-
this.tree.destroyTree(data.slug);
184+
// this.tree.destroyTree(data.slug);
177185

178186
const options = {
179187
staticHost: config.server.staticHost,
@@ -286,7 +294,7 @@ module.exports = class TutorialImporter {
286294

287295
data.githubLink = config.tutorialGithubBaseUrl + taskPath.slice(this.root.length);
288296

289-
this.tree.destroyTree(data.slug);
297+
//this.tree.destroyTree(data.slug);
290298

291299
const options = {
292300
staticHost: config.server.staticHost,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
modern_javascript_tutorial: "The Modern Javascript Tutorial"
22
subtitle: "From the basics to advanced topics, using simple, but detailed explanations."
3+
part: "Part #{num}"
4+
more: "More…"
5+
6+
part3:
7+
title: "Additional articles"
8+
content: "List of extra topics that are not covered by first two parts of tutorial. There is no clear hierarchy here, you can access articles in the order you want."
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
modern_javascript_tutorial: "Современный учебник Javascript"
22
subtitle: "Перед вами учебник по JavaScript, начиная с основ, включающий в себя много тонкостей и фишек JavaScript/DOM."
3+
part: "Часть #{num}"
4+
more: "Далее…"
5+
6+
7+
part3:
8+
title: "Additional articles"
9+
content: "List of extra topics that are not covered by first two parts of tutorial. There is no clear hierarchy here, you can access articles in the order you want."

handlers/tutorial/models/tutorialTree.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ module.exports = class TutorialTree {
7373

7474
if (!entry) return;
7575

76+
// console.log("DESTROY", slug);
77+
7678
if (entry.children) {
7779
for (let childSlug of entry.children) {
7880
this.destroyTree(childSlug);
@@ -91,7 +93,10 @@ module.exports = class TutorialTree {
9193
}
9294

9395
add(entry) {
94-
if (this.bySlug(entry)) {
96+
97+
// console.log("ADD", entry.slug, "CHECK", this.bySlug(entry.slug));
98+
99+
if (this.bySlug(entry.slug)) {
95100
throw new Error("Already exists an entry with slug:" + entry.slug);
96101
}
97102

@@ -112,6 +117,7 @@ module.exports = class TutorialTree {
112117
siblings.splice(i, 0, entry.slug);
113118

114119
}
120+
115121
}
116122

117123

handlers/tutorial/tasks/importWatch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function watchTutorial() {
8787
folder = path.dirname(filePath);
8888
}
8989

90-
importer.sync(folder).catch(function(err) {
90+
importer.sync(folder, true).catch(function(err) {
9191
log.error(err);
9292
});
9393
}

handlers/tutorial/templates/blocks/main-en-contents/index.pug

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)