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

Skip to content

Commit 6d7a34d

Browse files
committed
Initial commit
0 parents  commit 6d7a34d

16 files changed

+346
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
node_modules
3+
content/.links_checked.json
4+
content/links_failed.json

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# NativeScript-Vue website
2+
3+
This is a WIP statically generated website

build/index.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
const path = require('path');
2+
3+
const Metalsmith = require('metalsmith');
4+
5+
// plugins
6+
const multiLanguage = require('metalsmith-multi-language');
7+
const collections = require('metalsmith-collections');
8+
const permalinks = require('metalsmith-permalinks');
9+
const linkcheck = require('metalsmith-linkcheck');
10+
const dates = require('metalsmith-jekyll-dates');
11+
const inPlace = require('metalsmith-in-place');
12+
const layouts = require('metalsmith-layouts');
13+
const watch = require('metalsmith-watch');
14+
const when = require('metalsmith-if');
15+
16+
// custom plugins
17+
const changeExt = require('./plugins/change-ext');
18+
const markdown = require('./plugins/markdown');
19+
const toc = require('./plugins/toc');
20+
21+
const isDev = process.argv[2] === '--dev';
22+
const cwd = path.resolve(__dirname, '..');
23+
24+
Metalsmith(cwd)
25+
// set globally available metadata
26+
.metadata({
27+
sitename: 'NativeScript-Vue',
28+
siteurl: 'https://nativescript-vue.org/',
29+
description: 'Build truly native apps using Vue.js'
30+
})
31+
// look for files in the content directory
32+
.source('./content')
33+
// output files to the dist directory
34+
.destination('./dist')
35+
// clean the dist directory before building
36+
.clean(true)
37+
// ignore directories and files starting with an _
38+
.ignore([
39+
'_**/*',
40+
'**/_*',
41+
])
42+
// watch the content dir when in dev mode (--dev)
43+
.use(when(isDev, watch({
44+
paths: {
45+
"${source}/**/*.{md, ejs}": true,
46+
"layouts/**/*": '**/*.md',
47+
}
48+
})))
49+
// group certain files into collections
50+
.use(collections({
51+
blog: 'blog/*.md',
52+
docs: {
53+
pattern: 'docs/**/*.md',
54+
refer: false
55+
}
56+
}))
57+
// use jekyll style dates in the file names
58+
.use(dates())
59+
// use multiple languages
60+
.use(multiLanguage({
61+
default: 'en',
62+
locales: ['en', 'hu']
63+
}))
64+
// render markdown using our own plugin around marked
65+
.use(markdown())
66+
// add table of contents using our own plugin
67+
.use(toc())
68+
// generate the final files to have pretty urls
69+
.use(permalinks({
70+
relative: false,
71+
72+
linksets: [
73+
{
74+
match: {collection: 'blog'},
75+
pattern: 'blog/:date/:slug',
76+
},
77+
{
78+
match: {collection: 'docs'},
79+
pattern: ':locale/docs/:title'
80+
}
81+
]
82+
}))
83+
// allow inPlace to process files
84+
.use(changeExt({
85+
pattern: `*.html`,
86+
ext: '.ejs'
87+
}))
88+
// wrap content in handlebars layouts
89+
.use(layouts({
90+
engine: 'ejs',
91+
default: 'default.ejs',
92+
partials: 'layouts/_partials',
93+
partialExtension: '.ejs',
94+
rename: false
95+
}))
96+
// allow using template features inside the content directory
97+
.use(inPlace({
98+
engineOptions: {
99+
partials: 'layouts/_partials',
100+
}
101+
}))
102+
// finally check if we have broken links
103+
.use(linkcheck({
104+
failMissing: false
105+
}))
106+
// build the site
107+
.build((err) => {
108+
if (err) {
109+
console.log(err.toString())
110+
}
111+
});

build/plugins/change-ext.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const multimatch = require('multimatch');
2+
const path = require('path');
3+
4+
function plugin(opts) {
5+
6+
return function (files, metalsmith, done) {
7+
Object.keys(files).forEach((file) => {
8+
if (multimatch(file, opts.pattern).length) {
9+
const data = files[file];
10+
const new_name = path.extname(file) + opts.ext;
11+
delete files[file];
12+
files[new_name] = data;
13+
}
14+
});
15+
16+
done();
17+
}
18+
}
19+
20+
module.exports = plugin;

build/plugins/markdown.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const marked = require('marked');
2+
3+
// allow injecting partials
4+
// from: > partial:partialname
5+
// to: {{> partialname }}
6+
function handlebarPartials(renderer) {
7+
((b) => {
8+
renderer.blockquote = (quote) => {
9+
const match = quote.match(/<p>partial:(.+)<\/p>/);
10+
if (match) {
11+
return `{{> ${match[1]} }}`
12+
} else {
13+
return b(quote)
14+
}
15+
}
16+
})(renderer.blockquote);
17+
}
18+
19+
function plugin(opts) {
20+
const renderer = new marked.Renderer();
21+
22+
renderer.heading = function(text, level, raw) {
23+
let parsed = parseAnchor(raw);
24+
let id = parsed.id;
25+
26+
return (
27+
`<h${level} class="header">` +
28+
`<a class="anchor" href="#${id}" id="${id}"></a>` +
29+
`<a class="icon-link" href="#${id}">${text}</a>` +
30+
`</h${level}>\n`
31+
);
32+
};
33+
34+
handlebarPartials(renderer);
35+
36+
marked.setOptions(Object.assign({renderer}, opts));
37+
38+
return function (files, metalsmith, done) {
39+
40+
Object.keys(files).forEach((file) => {
41+
if (!file.endsWith('.md')) {
42+
return
43+
}
44+
45+
const data = files[file];
46+
const new_name = file.replace('.md', '.html');
47+
48+
if (data.extends) {
49+
// console.log('should extend though...')
50+
}
51+
52+
data.contents = new Buffer(marked(data.contents.toString()));
53+
delete files[file];
54+
files[new_name] = data;
55+
});
56+
57+
done();
58+
}
59+
}
60+
61+
function parseAnchor(string) {
62+
var stripped = string.replace(/\[(.+)\]\(.+\)/gi, '$1').replace(/(<([^>]+)>)/ig, '');
63+
var clean = stripped.replace(/`/g, '');
64+
65+
return {
66+
title: clean,
67+
id: clean.replace(/[^\w]+/g, '-').toLowerCase()
68+
};
69+
}
70+
71+
module.exports = plugin;

build/plugins/toc.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
const tocJSON = require('table-of-contents-json');
4+
5+
6+
function plugin(opts) {
7+
8+
9+
return function (files, metalsmith, done) {
10+
Object.keys(files).forEach((file) => {
11+
const data = files[file];
12+
13+
if (data.toc === true) {
14+
try {
15+
data.toc = new tocJSON().generateJSON(data.contents.toString());
16+
} catch (err) {
17+
return done(err);
18+
}
19+
} else if (!!data.toc) {
20+
const tocPath = path.resolve(metalsmith._source, data.paths.dir, data.toc);
21+
try {
22+
const toc = fs.readFileSync(tocPath);
23+
data.toc = JSON.parse(toc);
24+
} catch (err) {
25+
done(err);
26+
}
27+
} else {
28+
data.toc = false;
29+
}
30+
});
31+
done();
32+
}
33+
}
34+
35+
module.exports = plugin;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: We have a new site!
3+
authors: [rigor789]
4+
---
5+
6+
# This is our first post!
7+
8+
Posts are written in markdown...

content/docs/en/_toc.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"name": "Introduction",
4+
"type": "main-category",
5+
"children": [
6+
{
7+
"name": "Welcome",
8+
"type": "link",
9+
"children": []
10+
}
11+
]
12+
}
13+
]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: About NativeScript-Vue
3+
contributors: [rigor789]
4+
---
5+
6+
# What is NativeScript?
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Installing NativeScript
3+
extends: https://raw.githubusercontent.com/NativeScript/docs/master/docs/start/quick-setup.md
4+
---
5+
6+
# step 1

content/index_en.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Index

content/index_hu.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HU HOME

layouts/_partials/contributors.ejs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h1>Contributors</h1>
2+
3+
<ul>
4+
<% contributors.forEach((contributor) => { %>
5+
<li><%= contributor %></li>
6+
<% }) %>
7+
</ul>

layouts/_partials/links.ejs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<ul>
2+
<% posts.forEach((post) => { %>
3+
<li>
4+
<a href="/<%= post.path %>"><%= post.title %></a>
5+
</li>
6+
<% }) %>
7+
</ul>

layouts/default.ejs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title><%= sitename %></title>
9+
</head>
10+
<body>
11+
<%- contents %>
12+
13+
<div>
14+
<%- include('_partials/links', { posts: collections.blog }) %>
15+
<%- include('_partials/links', { posts: collections.docs }) %>
16+
</div>
17+
18+
<% if(typeof contributors !== 'undefined') { %>
19+
<%- include('_partials/contributors', contributors) %>
20+
<% } %>
21+
</body>
22+
</html>

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "nativescript-vue-docs-metalsmith",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"dev": "node build/index.js --dev",
8+
"build": "node build/index.js"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"ejs": "^2.5.7",
15+
"jstransformer-ejs": "0.0.3",
16+
"marked": "^0.3.9",
17+
"metalsmith": "^2.3.0",
18+
"metalsmith-collections": "^0.9.0",
19+
"metalsmith-if": "^0.1.1",
20+
"metalsmith-ignore": "^0.1.2",
21+
"metalsmith-in-place": "^3.0.1",
22+
"metalsmith-jekyll-dates": "0.0.5",
23+
"metalsmith-layouts": "^1.8.1",
24+
"metalsmith-linkcheck": "^0.3.0",
25+
"metalsmith-multi-language": "^0.3.0",
26+
"metalsmith-permalinks": "^0.5.0",
27+
"metalsmith-watch": "^1.0.3",
28+
"multimatch": "^2.1.0",
29+
"table-of-contents-json": "^1.2.0"
30+
}
31+
}

0 commit comments

Comments
 (0)