Skip to content

Commit ecd2c5e

Browse files
committed
wip, also first commit in 2018!
1 parent d6f13a6 commit ecd2c5e

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

build/plugins/locales.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,51 @@ function plugin(opts) {
1111
// set global information about the available locales
1212
const defaultLocale = meta.defaultLocale = opts.defaultLocale;
1313
const locales = meta.locales = opts.locales;
14+
15+
// creates a pattern for the given locales
1416
const pattern = (locales) => {
1517
if (!Array.isArray(locales)) {
1618
locales = [locales]
1719
}
18-
1920
return new RegExp(`.*\\/(?:${locales.join('|')})\\/(.+)(\\..+)`)
2021
};
2122

23+
// creates a list of required files based on the default locale
2224
const requiredFiles = Object.keys(files)
2325
.filter(file => file.match(pattern(defaultLocale)))
2426
.map(file => {
2527
return file.replace(`${path.sep}${defaultLocale}${path.sep}`, `${path.sep}{LOCALE}${path.sep}`);
2628
});
29+
2730
const otherLocales = locales.filter(l => l !== defaultLocale);
2831

32+
// builds out the file structure for all the other locales
2933
otherLocales.forEach((locale) => {
34+
3035
requiredFiles.forEach((file) => {
36+
const original_file = file.replace('{LOCALE}', defaultLocale);
37+
console.log(original_file);
38+
3139
const new_file = file.replace('{LOCALE}', locale);
32-
const dir = path.dirname(file);
40+
const new_file_path = path.resolve(sourcePath, new_file);
41+
const dir = path.dirname(new_file_path);
42+
3343
mkdirp(dir, (err) => {
3444
if (err) throw err;
35-
const exists = fs.existsSync(new_file);
36-
if (!exists) {
37-
fs.writeFileSync(new_file, files[file.replace('{LOCALE}', defaultLocale)].contents, () => {
38-
console.log('Written new file at ', new_file)
39-
})
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+
});
4053
}
4154
})
4255
})
4356
});
44-
console.log(otherLocales, requiredFiles)
45-
// console.log(path.resolve(sourcePath, defaultLocale));
46-
4757

48-
// done();
58+
done();
4959
}
5060
}
5161

build/plugins/order.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ function plugin() {
44

55
return function (files, metalsmith, done) {
66
Object.keys(files).forEach((file) => {
7+
if (!file.includes('docs')) {
8+
return
9+
}
10+
711
const res = path.basename(file).match(/^(\d+)-/);
812
if (res) {
9-
files[file].order = res[1];
13+
const data = files[file];
14+
data.order = res[1];
15+
16+
// rename file to not include the order
17+
files[file.replace(res[0], '')] = data;
1018
}
1119
});
1220
done();

content/docs/en/_toc.json

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy