From aab2b08ccd136ad810a516a25adf4daba980cde1 Mon Sep 17 00:00:00 2001 From: amad-person Date: Sun, 17 Feb 2019 21:51:03 +0800 Subject: [PATCH 01/17] Add initial prototype of wiki conversion --- index.js | 14 +++- src/Site.js | 179 +++++++++++++++++++++++++++++++++++++++++++++ src/util/fsUtil.js | 8 ++ 3 files changed, 200 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ff4d28d878..b3bbf78e73 100755 --- a/index.js +++ b/index.js @@ -45,15 +45,27 @@ program program .command('init [root]') + .option('-c, --convert', 'convert a Github wiki or docs folder to a MarkBind website') .alias('i') .description('init a markbind website project') - .action((root) => { + .action((root, options) => { const rootFolder = path.resolve(root || process.cwd()); + const outputRoot = path.join(rootFolder, '_site'); printHeader(); Site.initSite(rootFolder) .then(() => { logger.info('Initialization success.'); }) + .then(() => { + if (options.convert) { + logger.info('Converting to MarkBind website.'); + new Site(rootFolder, outputRoot).convert() + .then(() => { + logger.info('Conversion success.'); + }) + .catch(handleError); + } + }) .catch(handleError); }); diff --git a/src/Site.js b/src/Site.js index 2684a00a5a..aa4e44c975 100644 --- a/src/Site.js +++ b/src/Site.js @@ -18,6 +18,7 @@ _.isBoolean = require('lodash/isBoolean'); _.isUndefined = require('lodash/isUndefined'); _.noop = require('lodash/noop'); _.omitBy = require('lodash/omitBy'); +_.startCase = require('lodash/startCase'); _.union = require('lodash/union'); _.uniq = require('lodash/uniq'); @@ -25,6 +26,7 @@ const url = {}; url.join = path.posix.join; const delay = require('./util/delay'); +const FsUtil = require('./util/fsUtil'); const logger = require('./util/logger'); const Page = require('./Page'); @@ -38,6 +40,7 @@ const TEMP_FOLDER_NAME = '.temp'; const TEMPLATE_ROOT_FOLDER_NAME = 'template'; const TEMPLATE_SITE_ASSET_FOLDER_NAME = 'markbind'; +const ABOUT_MARKDOWN_FILE = 'about.md'; const BUILT_IN_PLUGIN_FOLDER_NAME = 'plugins'; const BUILT_IN_DEFAULT_PLUGIN_FOLDER_NAME = 'plugins/default'; const FAVICON_DEFAULT_PATH = 'favicon.ico'; @@ -53,12 +56,15 @@ const PROJECT_PLUGIN_FOLDER_NAME = '_markbind/plugins'; const SITE_CONFIG_NAME = 'site.json'; const SITE_DATA_NAME = 'siteData.json'; const SITE_NAV_PATH = '_markbind/navigation/site-nav.md'; +const TOP_NAV_PATH = '_markbind/common/topNav.md'; const LAYOUT_DEFAULT_NAME = 'default'; const LAYOUT_FILES = ['navigation.md', 'head.md', 'footer.md', 'header.md', 'styles.css']; const LAYOUT_FOLDER_PATH = '_markbind/layouts'; const LAYOUT_SCRIPTS_PATH = 'scripts.js'; const LAYOUT_SITE_FOLDER_NAME = 'layouts'; const USER_VARIABLES_PATH = '_markbind/variables.md'; +const WIKI_SITE_NAV_PATH = '_Sidebar.md'; +const WIKI_FOOTER_PATH = '_Footer.md'; function getBootswatchThemePath(theme) { return path.join(__dirname, '..', 'node_modules', 'bootswatch', 'dist', theme, 'bootstrap.min.css'); @@ -114,6 +120,9 @@ const SITE_CONFIG_DEFAULT = { }, }; +const ABOUT_MARKDOWN_DEFAULT = '# About\n' + + 'Welcome to your **About Us** page.\n'; + const FOOTER_DEFAULT = '