Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 4d96fbd

Browse files
committed
Create variables.md in initSite
1 parent 788c39b commit 4d96fbd

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

lib/Site.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const BOILERPLATE_FOLDER_NAME = '_boilerplates';
1818
const SITE_ASSET_FOLDER_NAME = 'asset';
1919
const TEMPLATE_ROOT_FOLDER_NAME = 'template';
2020
const TEMPLATE_SITE_ASSET_FOLDER_NAME = 'markbind';
21-
const USER_VARIABLES_PATH = '_system/variables.md';
21+
const USER_VARIABLES_PATH = '_markbind/variables.md';
2222

2323
const SITE_CONFIG_DEFAULT = {
2424
baseUrl: '',
@@ -40,6 +40,11 @@ const SITE_CONFIG_DEFAULT = {
4040

4141
const INDEX_MARKDOWN_DEFAULT = '# Hello world\nWelcome to your page generated with MarkBind.\n';
4242

43+
const USER_VARIABLES_DEFAULT = '<span id="example">\n'
44+
+ 'To inject this HTML segment in your markbind files, use {{ example }} where you want to place it.\n'
45+
+ 'More generally, surround the segment\'s id with double curly braces.\n'
46+
+ '</span>';
47+
4348
function Site(rootPath, outputPath) {
4449
this.rootPath = rootPath;
4550
this.outputPath = outputPath;
@@ -86,6 +91,7 @@ Site.initSite = function (rootPath) {
8691
const boilerplatePath = path.join(rootPath, BOILERPLATE_FOLDER_NAME);
8792
const configPath = path.join(rootPath, SITE_CONFIG_NAME);
8893
const indexPath = path.join(rootPath, INDEX_MARKDOWN_FILE);
94+
const userDefinedVariablesPath = path.join(rootPath, USER_VARIABLES_PATH);
8995
// TODO: log the generate info
9096
return new Promise((resolve, reject) => {
9197
fs.accessAsync(boilerplatePath)
@@ -109,6 +115,13 @@ Site.initSite = function (rootPath) {
109115
}
110116
return fs.outputFileAsync(indexPath, INDEX_MARKDOWN_DEFAULT);
111117
})
118+
.then(() => fs.accessAsync(userDefinedVariablesPath))
119+
.catch(() => {
120+
if (fs.existsSync(userDefinedVariablesPath)) {
121+
return Promise.resolve();
122+
}
123+
return fs.outputFileAsync(userDefinedVariablesPath, USER_VARIABLES_DEFAULT);
124+
})
112125
.then(resolve)
113126
.catch(reject);
114127
});

0 commit comments

Comments
 (0)