From 241b766bad14d7b97e839018d56829365506592b Mon Sep 17 00:00:00 2001 From: Oleg Kalachev Date: Sat, 9 Apr 2022 07:32:58 +0400 Subject: [PATCH] Start working on transferring to VuePress --- .gitignore | 2 ++ docs/.vuepress/config.js | 56 ++++++++++++++++++++++++++++++++ docs/.vuepress/sidebar.js | 47 +++++++++++++++++++++++++++ docs/.vuepress/styles/index.scss | 11 +++++++ docs/README.md | 4 +++ docs/en/README.md | 3 +- docs/package.json | 13 ++++++++ docs/ru/README.md | 2 +- 8 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 docs/.vuepress/config.js create mode 100644 docs/.vuepress/sidebar.js create mode 100644 docs/.vuepress/styles/index.scss create mode 100644 docs/README.md create mode 100644 docs/package.json diff --git a/.gitignore b/.gitignore index 042b71c9..78c196c4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ package-lock.json clover_blocks/programs/*.* !clover_blocks/programs/examples/* /.vscode/ +docs/.vuepress/.cache/ +docs/.vuepress/.temp/ diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js new file mode 100644 index 00000000..f128dcca --- /dev/null +++ b/docs/.vuepress/config.js @@ -0,0 +1,56 @@ +const glob = require('glob'); +const sidebar = require('./sidebar'); + +console.log(__dirname + '/..'); +let markdownFiles = glob.sync('ru/*.md', { cwd: __dirname + '/..' }).map(f => '/' + f); + +module.exports = { + // site config + lang: 'en-US', + title: 'Clover', + description: 'Clover Drone Kit', + // theme and its config + theme: '@vuepress/theme-default', + themeConfig: { + logo: 'https://vuejs.org/images/logo.png', + // sidebar: markdownFiles + sidebar: { + '/ru/': sidebar.readSummary("./ru/SUMMARY.md"), + '/en/': sidebar.readSummary("./en/SUMMARY.md"), + }, + sidebarDepth: 0, + locales: { + '/en/': { selectLanguageName: 'English' }, + '/ru/': { selectLanguageName: 'Русский' }, + } + }, + locales: { + // The key is the path for the locale to be nested under. + // As a special case, the default locale can use '/' as its path. + // '/en': { + // lang: 'en-US', + // title: 'Clover', + // description: 'Clover Drone Kit' + // }, + '/en/': { + lang: 'en', + title: 'Clover', + description: 'Clover Drone Kit' + }, + '/ru/': { + lang: 'ru', + title: 'Клевер', + description: 'Конструктор квадрокоптера «Клевер»' + } + }, + markdown: { + code: { + lineNumbers: false + } + }, + plugins: [ + '@vuepress/plugin-search', + 'vuepress-plugin-copy-code2' + // ['@vuepress/plugin-search', {}] + ] +} diff --git a/docs/.vuepress/sidebar.js b/docs/.vuepress/sidebar.js new file mode 100644 index 00000000..8ff6dab7 --- /dev/null +++ b/docs/.vuepress/sidebar.js @@ -0,0 +1,47 @@ +const fs = require('fs') + +const regex = /(\s*?)\*\s\[(.*?)\]\((.*?)\)/; + +exports.readSummary = function (path) { + let sidebar = []; + let lines = fs.readFileSync(path).toString().split('\n'); + let item = {}; + + for (let line of lines) { + if (line.startsWith('#')) continue; + if (!line.trim()) continue; + + let match = regex.exec(line); + if (!match) { + console.log('cannot parse', line); + continue; + } + level = match[1].length / 2; + text = match[2]; + path = match[3].trim(); + + if (level == 0) { + if (item.path) { + // push new item + if (item.children) { + sidebar.push(item); + } else { + sidebar.push(item.path) + } + item = {}; + } + item.text = text; + item.path = path; + item.collapsible = true; + + } else if (level == 1) { + if (!item.children) item.children = []; + item.children.push(path); + + } else { + console.log('skip', text); + } + } + + return sidebar; +} diff --git a/docs/.vuepress/styles/index.scss b/docs/.vuepress/styles/index.scss new file mode 100644 index 00000000..2a701bd3 --- /dev/null +++ b/docs/.vuepress/styles/index.scss @@ -0,0 +1,11 @@ +.big-clover { + max-width: 80% !important; + display: block; + margin-left: auto; + margin-right: auto; +} + +/* change image for dark theme */ +html .big-clover.dark { display: none; } +html.dark .big-clover { display: none; } +html.dark .big-clover.dark { display: block; } diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..e3fd6fc1 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,4 @@ +# Languages + +* [English](en/) +* [Русский](ru/) diff --git a/docs/en/README.md b/docs/en/README.md index 940eed4b..67d44a84 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -1,6 +1,7 @@ # COEX Clover -Clover 4.2 +Clover 4.2 +Clover 4.2 **Clover** is an educational kit of a programmable quadcopter that consists of popular open source components, and a set of necessary documentation and libraries for working with it. diff --git a/docs/package.json b/docs/package.json new file mode 100644 index 00000000..92853a7a --- /dev/null +++ b/docs/package.json @@ -0,0 +1,13 @@ +{ + "devDependencies": { + "@vuepress/plugin-search": "^2.0.0-beta.38", + "glob": "^7.2.0", + "vuepress": "^2.0.0-beta.38", + "vuepress-plugin-copy-code2": "^2.0.0-beta.36" + }, + "scripts": { + "dev": "vuepress dev .", + "build": "vuepress build .", + "clear": "vuepress clear ." + } +} diff --git a/docs/ru/README.md b/docs/ru/README.md index e0dbe5fc..b63c2440 100644 --- a/docs/ru/README.md +++ b/docs/ru/README.md @@ -1,6 +1,6 @@ # Клевер -Клевер 4.2 +Клевер 4.2 **«Клевер»** — это учебный конструктор программируемого квадрокоптера, состоящего из популярных открытых компонентов, а также набор необходимой документации и библиотек для работы с ним.