Skip to content

Commit a30b93b

Browse files
committed
wip
1 parent 47ed550 commit a30b93b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+186
-82
lines changed

build/index.js

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
const path = require('path');
22

33
const Metalsmith = require('metalsmith');
4+
const multimatch = require('multimatch');
45

56
// plugins
6-
const multiLanguage = require('metalsmith-multi-language');
77
const collections = require('metalsmith-collections');
8-
const permalinks = require('metalsmith-permalinks');
98
const linkcheck = require('metalsmith-linkcheck');
109
const dates = require('metalsmith-jekyll-dates');
1110
const assets = require('metalsmith-assets');
@@ -16,8 +15,9 @@ const moment = require('moment');
1615
// custom plugins
1716
const link_index = require('./plugins/link_index');
1817
const categories = require('./plugins/categories');
18+
const permalinks = require('./plugins/permalinks');
1919
const changeExt = require('./plugins/change-ext');
20-
const markdown = require('./plugins/markdown');
20+
const markdown = require('./plugins/remark');
2121
const locales = require('./plugins/locales');
2222
const layouts = require('./plugins/layouts');
2323
const order = require('./plugins/order');
@@ -32,7 +32,23 @@ Metalsmith(cwd)
3232
sitename: 'NativeScript-Vue',
3333
siteurl: 'https://nativescript-vue.org/',
3434
description: 'Build truly native apps using Vue.js',
35-
moment
35+
moment,
36+
lang(locale) {
37+
const found = this.links.find(l => l.endsWith(`${this.slug}/index.html`) && l.includes(locale));
38+
if(found) {
39+
return found;
40+
}
41+
return `/${locale === 'en' ? '' : locale}`;
42+
}
43+
})
44+
.use((files, metalsmith, done) => {
45+
metalsmith.matches = (name, pattern) => multimatch(name, pattern).length > 0;
46+
metalsmith.rename = (file, to) => {
47+
const data = files[file];
48+
delete files[file];
49+
files[to] = data;
50+
};
51+
done();
3652
})
3753
// look for files in the content directory
3854
.source('./content')
@@ -42,8 +58,9 @@ Metalsmith(cwd)
4258
.clean(true)
4359
// ignore directories and files starting with an _
4460
.ignore([
45-
'_**/*',
46-
'**/_*',
61+
'_**',
62+
'.**',
63+
'**.json',
4764
])
4865
// watch the content dir when in dev mode (--dev)
4966
.use(when(isDev, watch({
@@ -52,23 +69,24 @@ Metalsmith(cwd)
5269
"layouts/**/*": '**/*.md',
5370
}
5471
})))
72+
.use(order())
5573
.use(locales({
5674
defaultLocale: 'en',
57-
locales: ['en', 'hu']
75+
locales: ['en']
5876
}))
59-
.use(order())
6077
.use(categories())
6178
// group certain files into collections
6279
.use(collections({
6380
blog: {
6481
pattern: 'blog/*.md',
6582
sortBy: 'date',
6683
reverse: true,
84+
refer: false
6785
},
6886
docs: {
6987
pattern: 'docs/**/*.md',
7088
sortBy: 'order',
71-
refer: true
89+
refer: false
7290
}
7391
}))
7492
// use jekyll style dates in the file names
@@ -84,19 +102,18 @@ Metalsmith(cwd)
84102
.use(toc())
85103
// generate the final files to have pretty urls
86104
.use(permalinks({
87-
relative: false,
88-
89-
linksets: [
105+
sets: [
90106
{
91-
match: {collection: 'blog'},
92-
pattern: 'blog/:date/:slug',
107+
pattern: 'blog/**/*',
108+
format: 'blog/:slug',
93109
},
94110
{
95-
match: {collection: 'docs'},
96-
pattern: ':locale/docs/:title'
111+
pattern: 'docs/**/*',
112+
format: ':locale/docs/:slug/index.html'
97113
}
98114
]
99115
}))
116+
.use(link_index())
100117
// render all files in side a layout if specified
101118
.use(layouts({
102119
default: 'post.ejs',
@@ -124,7 +141,6 @@ Metalsmith(cwd)
124141
.use(linkcheck({
125142
failMissing: false
126143
}))
127-
.use(link_index())
128144
// build the site
129145
.build((err) => {
130146
if (err) {

build/plugins/link_index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function plugin(opts) {
1010
}
1111
});
1212

13-
// console.log(links);
13+
metalsmith.metadata().links = links;
1414
done();
1515
}
1616
}

build/plugins/locales.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function plugin(opts) {
1919
if (!Array.isArray(locales)) {
2020
locales = [locales]
2121
}
22-
return new RegExp(`.*\\/(?:${locales.join('|')})\\/(.+)(\\..+)`)
22+
return new RegExp(`.*\\/(${locales.join('|')})\\/(.+)(\\..+)`)
2323
};
2424

2525
// creates a list of required files based on the default locale
@@ -33,7 +33,6 @@ function plugin(opts) {
3333

3434
// builds out the file structure for all the other locales
3535
otherLocales.forEach((locale) => {
36-
3736
requiredFiles.forEach((file) => {
3837
const original_file = file.replace('{LOCALE}', defaultLocale);
3938

@@ -49,14 +48,23 @@ function plugin(opts) {
4948
fs.writeFileSync(new_file_path, contents);
5049

5150
new_files[new_file] = Object.assign({}, data, {
52-
contents: new Buffer(contents)
51+
contents: new Buffer(contents),
52+
locale: locale
5353
});
5454
}
5555
})
5656
});
5757

5858
Object.assign(files, new_files);
5959

60+
Object.keys(files).forEach(file => {
61+
const res = file.match(pattern(locales));
62+
if (res) {
63+
files[file].locale = res[1];
64+
files[file].slug = res[2];
65+
}
66+
});
67+
6068
if (!!Object.keys(new_files).length) {
6169
console.log(chalk.yellow('-'.repeat(process.stdout.columns)));
6270
console.log(chalk.green('Missing locale files have been detected.'));

build/plugins/order.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ function plugin() {
1414
data.order = res[1];
1515

1616
// rename file to not include the order
17-
files[file.replace(res[0], '')] = data;
18-
delete files[file];
17+
metalsmith.rename(file, file.replace(res[0], ''));
1918
}
2019
});
2120
done();

build/plugins/permalinks.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const Permalinks = require('permalinks');
2+
3+
module.exports = function permalinks(options = {}) {
4+
const opts = Object.assign({}, {
5+
format: ':name/index.html',
6+
sets: []
7+
}, options);
8+
9+
const pl = new Permalinks();
10+
11+
return (files, metalsmith, done) => {
12+
Object.keys(files).forEach((file) => {
13+
const set = opts.sets.find(set => metalsmith.matches(file, set.pattern));
14+
let format = (set && set.format) || opts.format;
15+
16+
try {
17+
if (file.includes('index.')) {
18+
format = format.replace('/index.html', '.html');
19+
}
20+
21+
const l = pl.format(format, file, files[file]);
22+
files[file].path = l;
23+
metalsmith.rename(file, l)
24+
} catch (err) {
25+
done(err);
26+
}
27+
});
28+
done();
29+
}
30+
};

build/plugins/remark.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const remark = require('remark');
2+
const lint = require('remark-preset-lint-recommended');
3+
const html = require('remark-html');
4+
const report = require('vfile-reporter');
5+
6+
function processMarkdown(contents) {
7+
return new Promise((resolve, reject) => {
8+
remark()
9+
.use(lint)
10+
.use(html)
11+
.process(contents, (err, file) => {
12+
if (err) reject(err);
13+
14+
resolve(file);
15+
})
16+
})
17+
}
18+
19+
module.exports = function permalinks(options = {}) {
20+
const opts = Object.assign({}, {
21+
pattern: '**/*.md',
22+
rename: true
23+
}, options);
24+
25+
return async (files, metalsmith, done) => {
26+
for (file of Object.keys(files)) {
27+
const data = files[file];
28+
29+
if (!metalsmith.matches(file, opts.pattern)) {
30+
continue;
31+
}
32+
33+
try {
34+
const res = await processMarkdown(data.contents);
35+
36+
if (res.messages.length > 0) {
37+
// console.log(`${file}:\n${report(res)}`);
38+
}
39+
data.contents = res.toString();
40+
} catch (err) {
41+
console.log(`${file}: ${report(err)}`);
42+
43+
done(err);
44+
}
45+
}
46+
47+
done();
48+
}
49+
};

content/blog/2017-12-22-we-have-a-new-site.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ console.log('????');
1616
console.log('helllooo??? why is this not working????');
1717
```
1818

19-
but in the end it turned out great.
19+
but in the end it turned out great.

content/blog/2017-12-24-code-sharing-coming-soon.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ toc: true
66

77
One of our biggest goals is to allow developers to write
88
their web and mobile applications by sharing most of the
9-
business logic.
9+
business logic.

content/docs/en/1-quick-start.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,3 @@ or
7171
```sh
7272
tns run ios
7373
```
74-

content/docs/en/10-articles.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ contributors: [rdlauer, naderio]
66
- [A new Vue for NativeScript](https://www.nativescript.org/blog/a-new-vue-for-nativescript)
77
- [Vue.js and NativeScript in One Minute](https://www.nativescript.org/blog/vue-and-nativescript-in-one-minute)
88
- [Building Native iOS and Android Apps With Vue and NativeScript](https://developer.telerik.com/products/nativescript/native-ios-android-vue-nativescript/)
9-
- [Native apps with Vue.js: Weex or NativeScript?
10-
](https://hackernoon.com/native-apps-with-vue-js-weex-or-nativescript-8d8f0bac041d)
11-
9+
- [Native apps with Vue.js: Weex or NativeScript?](https://hackernoon.com/native-apps-with-vue-js-weex-or-nativescript-8d8f0bac041d)

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