Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 641d789

Browse files
committed
wip
1 parent ecd2c5e commit 641d789

File tree

5 files changed

+32
-20
lines changed

5 files changed

+32
-20
lines changed

build/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ Metalsmith(cwd)
7474
// use jekyll style dates in the file names
7575
.use(dates())
7676
// use multiple languages
77-
.use(multiLanguage({
78-
default: 'en',
79-
locales: ['en']
80-
}))
77+
// .use(multiLanguage({
78+
// default: 'en',
79+
// locales: ['en']
80+
// }))
8181
// render markdown using our own plugin around marked
8282
.use(markdown())
8383
// add table of contents using our own plugin

build/plugins/locales.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
const path = require('path');
22
const mkdirp = require('mkdirp');
33
const fs = require('fs');
4+
const chalk = require('chalk');
45

56
function plugin(opts) {
67

78
return function (files, metalsmith, done) {
89
const meta = metalsmith.metadata();
910
const sourcePath = metalsmith.source();
11+
const new_files = {};
1012

1113
// set global information about the available locales
1214
const defaultLocale = meta.defaultLocale = opts.defaultLocale;
@@ -22,7 +24,7 @@ function plugin(opts) {
2224

2325
// creates a list of required files based on the default locale
2426
const requiredFiles = Object.keys(files)
25-
.filter(file => file.match(pattern(defaultLocale)))
27+
.filter(file => !!file.match(pattern(defaultLocale)))
2628
.map(file => {
2729
return file.replace(`${path.sep}${defaultLocale}${path.sep}`, `${path.sep}{LOCALE}${path.sep}`);
2830
});
@@ -34,27 +36,36 @@ function plugin(opts) {
3436

3537
requiredFiles.forEach((file) => {
3638
const original_file = file.replace('{LOCALE}', defaultLocale);
37-
console.log(original_file);
3839

3940
const new_file = file.replace('{LOCALE}', locale);
4041
const new_file_path = path.resolve(sourcePath, new_file);
4142
const dir = path.dirname(new_file_path);
43+
mkdirp.sync(dir);
4244

43-
mkdirp(dir, (err) => {
44-
if (err) throw err;
45-
if (!fs.existsSync(new_file_path)) {
46-
const data = files[original_file];
47-
const contents = data ? data.contents : '';
48-
fs.writeFileSync(new_file_path, contents);
49-
50-
files[new_file] = Object.assign({}, data, {
51-
contents: new Buffer(contents)
52-
});
53-
}
54-
})
45+
if (!fs.existsSync(new_file_path)) {
46+
const data = files[original_file];
47+
const contents = data ? data.contents : '';
48+
49+
fs.writeFileSync(new_file_path, contents);
50+
51+
new_files[new_file] = Object.assign({}, data, {
52+
contents: new Buffer(contents)
53+
});
54+
}
5555
})
5656
});
5757

58+
Object.assign(files, new_files);
59+
60+
if (!!Object.keys(new_files).length) {
61+
console.log(chalk.yellow('-'.repeat(process.stdout.columns)));
62+
console.log(chalk.green('Missing locale files have been detected.'));
63+
console.log(chalk.yellow('-'.repeat(process.stdout.columns)));
64+
}
65+
Object.keys(new_files).forEach((file) => {
66+
console.log(`${chalk.bgGreen.black(' CREATED ')} ${file}`);
67+
});
68+
5869
done();
5970
}
6071
}

build/plugins/order.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function plugin() {
1515

1616
// rename file to not include the order
1717
files[file.replace(res[0], '')] = data;
18+
delete files[file];
1819
}
1920
});
2021
done();

build/plugins/toc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ function plugin(opts) {
1717
} catch (err) {
1818
return done(err);
1919
}
20-
} else if (!!data.toc) {
20+
/* } else if (!!data.toc) {
2121
try {
2222
const tocPath = metalsmith.path(metalsmith._source, path.dirname(file), data.toc);
2323
const toc = fs.readFileSync(tocPath);
2424
data.toc = JSON.parse(toc);
2525
} catch (err) {
2626
done(err);
2727
}
28+
*/
2829
} else {
2930
data.toc = false;
3031
data.layout = data.layout || 'no_sidebar.ejs';

content/docs/en/6-templates.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
title: Templates
3-
toc: _toc.json
43
contributors: [rigor789, tralves]
54
---
65

0 commit comments

Comments
 (0)