From 4c3ab73e81ffc9ffa15dcc1f9bf6a9cab545852f Mon Sep 17 00:00:00 2001 From: dunwu Date: Fri, 18 Aug 2023 20:37:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .babelrc | 3 ++ .github/workflows/deploy.yml | 2 +- docs/.vuepress/config.js | 10 ++-- docs/.vuepress/config/htmlModules.js | 37 ++++++++++---- docs/.vuepress/enhanceApp.js | 56 ++++++++++++++++++++-- package.json | 20 ++++---- prettier.config.js | 10 ++++ scripts/deploy.sh | 2 +- utils/config.yml | 13 ++--- utils/editFrontmatter.js | 66 +++++++++++++------------ utils/modules/fn.js | 22 +++++---- utils/modules/readFileList.js | 72 +++++++++++++++------------- 12 files changed, 209 insertions(+), 104 deletions(-) create mode 100644 .babelrc create mode 100644 prettier.config.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..55754d0 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "compact": false +} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 36b705c..0401094 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: - node-version: [14.x] + node-version: [16.x] steps: # 使用的动作。格式:userName/repoName。作用:检出仓库,获取源码。 官方actions库:https://github.com/actions diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 2041792..b7d15e2 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -12,7 +12,10 @@ module.exports = { // 注入到页面 中的标签,格式[tagName, { attrName: attrValue }, innerHTML?] ['link', { rel: 'icon', href: '/img/favicon.ico' }], //favicons,资源放在public文件夹 ['meta', { name: 'keywords', content: 'vuepress,theme,blog,vdoing' }], - ['meta', { name: 'theme-color', content: '#11a8cd' }] // 移动浏览器主题颜色 + ['meta', { name: 'theme-color', content: '#11a8cd' }], // 移动浏览器主题颜色 + + ['meta', { name: 'wwads-cn-verify', content: 'mxqWx62nfQQ9ocT4e5DzISHzOWyF4s' }], // 广告相关,你可以去掉 + ['script', { src: 'https://cdn.wwads.cn/js/makemoney.js', type: 'text/javascript' }], // 广告相关,你可以去掉 ], markdown: { // lineNumbers: true, @@ -63,9 +66,10 @@ module.exports = { editLinkText: '📝 帮助改善此页面!', // 以下配置是Vdoing主题改动的和新增的配置 - sidebar: { mode: 'structuring', collapsable: false }, // 侧边栏 'structuring' | { mode: 'structuring', collapsable: Boolean} | 'auto' | 自定义 温馨提示:目录页数据依赖于结构化的侧边栏数据,如果你不设置为'structuring',将无法使用目录页 + sidebar: { mode: 'structuring', collapsable: true }, // 侧边栏 'structuring' | { mode: 'structuring', collapsable: + // Boolean} | 'auto' | 自定义 温馨提示:目录页数据依赖于结构化的侧边栏数据,如果你不设置为'structuring',将无法使用目录页 - // sidebarOpen: false, // 初始状态是否打开侧边栏,默认true + sidebarOpen: true, // 初始状态是否打开侧边栏,默认true updateBar: { // 最近更新栏 showToArticle: true // 显示到文章页底部,默认true diff --git a/docs/.vuepress/config/htmlModules.js b/docs/.vuepress/config/htmlModules.js index 5120f42..fc0a47e 100644 --- a/docs/.vuepress/config/htmlModules.js +++ b/docs/.vuepress/config/htmlModules.js @@ -20,25 +20,42 @@ module.exports = { // 万维广告 - pageB: ` -
- - `, + // pageT: ` + //
+ // + // `, windowRB: ` -
- ` + `, } // module.exports = { diff --git a/docs/.vuepress/enhanceApp.js b/docs/.vuepress/enhanceApp.js index 1589fa4..5bfa34f 100644 --- a/docs/.vuepress/enhanceApp.js +++ b/docs/.vuepress/enhanceApp.js @@ -1,9 +1,59 @@ -// import vue from 'vue/dist/vue.esm.browser' +/** + * to主题使用者:你可以去掉本文件的所有代码 + */ export default ({ Vue, // VuePress 正在使用的 Vue 构造函数 options, // 附加到根实例的一些选项 router, // 当前应用的路由实例 - siteData // 站点元数据 + siteData, // 站点元数据 + isServer // 当前应用配置是处于 服务端渲染 还是 客户端 }) => { - // window.Vue = vue // 使页面中可以使用Vue构造函数 (使页面中的vue demo生效) + + // 用于监控在路由变化时检查广告拦截器 (to主题使用者:你可以去掉本文件的所有代码) + if (!isServer) { + router.afterEach(() => { + //check if wwads' fire function was blocked after document is ready with 3s timeout (waiting the ad loading) + docReady(function () { + setTimeout(function () { + if (window._AdBlockInit === undefined) { + ABDetected(); + } + }, 3000); + }); + + // 删除事件改为隐藏事件 + setTimeout(() => { + const pageAD = document.querySelector('.page-wwads'); + if (!pageAD) return; + const btnEl = pageAD.querySelector('.wwads-hide'); + if (btnEl) { + btnEl.onclick = () => { + pageAD.style.display = 'none'; + } + } + // 显示广告模块 + if (pageAD.style.display === 'none') { + pageAD.style.display = 'flex'; + } + }, 900); + }) + } +} + + +function ABDetected() { + const h = "
为了本站的长期运营,请将我们的网站加入广告拦截器的白名单,感谢您的支持!如何添加白名单?广告
"; + const wwadsEl = document.getElementsByClassName("wwads-cn"); + const wwadsContentEl = document.querySelector('.wwads-content'); + if (wwadsEl[0] && !wwadsContentEl) { + wwadsEl[0].innerHTML = h; + } +}; + +//check document ready +function docReady(t) { + "complete" === document.readyState || + "interactive" === document.readyState + ? setTimeout(t, 1) + : document.addEventListener("DOMContentLoaded", t); } diff --git a/package.json b/package.json index 04e9173..41b3b67 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { - "name": "java-tutorial", + "name": "db-tutorial", "version": "1.0.0", "private": true, "scripts": { "clean": "rimraf docs/.temp", - "start": "vuepress dev docs", - "build": "vuepress build docs", + "start": "node --max_old_space_size=4096 ./node_modules/vuepress/cli.js dev docs", + "build": "node --max_old_space_size=4096 ./node_modules/vuepress/cli.js build docs", "deploy": "bash scripts/deploy.sh", "updateTheme": "yarn remove vuepress-theme-vdoing && rm -rf node_modules && yarn && yarn add vuepress-theme-vdoing -D", "editFm": "node utils/editFrontmatter.js", @@ -15,19 +15,23 @@ "view-info": "vuepress view-info ./ --temp docs/.temp" }, "devDependencies": { - "dayjs": "^1.9.7", - "inquirer": "^7.1.0", + "dayjs": "^1.11.7", + "inquirer": "^9.1.4", "json2yaml": "^1.1.0", - "vuepress": "1.9.2", + "markdownlint-cli": "^0.33.0", + "markdownlint-rule-emphasis-style": "^1.0.1", + "rimraf": "^4.1.2", + "vue-toasted": "^1.1.25", + "vuepress": "1.9.9", "vuepress-plugin-baidu-tongji": "^1.0.1", "vuepress-plugin-comment": "^0.7.3", "vuepress-plugin-demo-block": "^0.7.2", + "vuepress-plugin-flowchart": "^1.4.2", "vuepress-plugin-fulltext-search": "^2.2.1", "vuepress-plugin-one-click-copy": "^1.0.2", "vuepress-plugin-thirdparty-search": "^1.0.2", "vuepress-plugin-zooming": "^1.1.7", - "vuepress-plugin-flowchart": "^1.4.2", - "vuepress-theme-vdoing": "^1.10.3", + "vuepress-theme-vdoing": "^1.12.9", "yamljs": "^0.3.0", "markdownlint-cli": "^0.25.0", "markdownlint-rule-emphasis-style": "^1.0.1", diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000..c9848e7 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,10 @@ +/** + * @see https://prettier.io/docs/en/options.html + * @see https://prettier.io/docs/en/configuration.html + */ +module.exports = { + tabWidth: 2, + semi: false, + singleQuote: true, + trailingComma: 'none' +} diff --git a/scripts/deploy.sh b/scripts/deploy.sh index ba8e17a..678bbf2 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------------------------------ # gh-pages 部署脚本 -# @author Zhang Peng +# @author Zhang Peng # @since 2020/2/10 # ------------------------------------------------------------------------------ diff --git a/utils/config.yml b/utils/config.yml index 6fac6a2..d387646 100644 --- a/utils/config.yml +++ b/utils/config.yml @@ -1,14 +1,15 @@ -#批量添加和修改、删除front matter配置文件 +# 批量添加和修改、删除front matter配置文件 -# 需要批量处理的路径,docs文件夹内的文件夹 (数组。映射路径:docs/arr[0]/arr[1] ... ) +# 需要批量处理的路径,docs文件夹内的文件夹 (数组,映射路径:path[0]/path[1]/path[2] ... ) path: - docs # 第一个成员必须是docs # 要删除的字段 (数组) -delete: - # - test +delete: # - tags - # 要添加、修改front matter的数据 (front matter中没有的数据则添加,已有的数据则覆盖) + # 要添加、修改front matter的数据 (front matter中没有的数据则添加,已有的数据则覆盖) data: - article: false \ No newline at end of file + # author: + # name: xugaoyi + # link: https://github.com/xugaoyi diff --git a/utils/editFrontmatter.js b/utils/editFrontmatter.js index 8c223f4..0998bf3 100644 --- a/utils/editFrontmatter.js +++ b/utils/editFrontmatter.js @@ -1,41 +1,43 @@ /** * 批量添加和修改front matter ,需要配置 ./config.yml 文件。 */ -const fs = require('fs'); // 文件模块 -const path = require('path'); // 路径模块 -const matter = require('gray-matter'); // front matter解析器 https://github.com/jonschlinkert/gray-matter +const fs = require('fs') // 文件模块 +const path = require('path') // 路径模块 +const matter = require('gray-matter') // front matter解析器 https://github.com/jonschlinkert/gray-matter const jsonToYaml = require('json2yaml') const yamlToJs = require('yamljs') const inquirer = require('inquirer') // 命令行操作 const chalk = require('chalk') // 命令行打印美化 -const readFileList = require('./modules/readFileList'); -const { type, repairDate} = require('./modules/fn'); +const readFileList = require('./modules/readFileList') +const { type, repairDate } = require('./modules/fn') const log = console.log const configPath = path.join(__dirname, 'config.yml') // 配置文件的路径 -main(); +main() /** * 主体函数 */ async function main() { + const promptList = [ + { + type: 'confirm', + message: chalk.yellow('批量操作frontmatter有修改数据的风险,确定要继续吗?'), + name: 'edit' + } + ] + let edit = true - const promptList = [{ - type: "confirm", - message: chalk.yellow('批量操作frontmatter有修改数据的风险,确定要继续吗?'), - name: "edit", - }]; - let edit = true; - - await inquirer.prompt(promptList).then(answers => { + await inquirer.prompt(promptList).then((answers) => { edit = answers.edit }) - if(!edit) { // 退出操作 + if (!edit) { + // 退出操作 return } - + const config = yamlToJs.load(configPath) // 解析配置文件的数据转为js对象 if (type(config.path) !== 'array') { @@ -48,27 +50,26 @@ async function main() { return } - const filePath = path.join(__dirname, '..', ...config.path); // 要批量修改的文件路径 - const files = readFileList(filePath); // 读取所有md文件数据 + const filePath = path.join(__dirname, '..', ...config.path) // 要批量修改的文件路径 + const files = readFileList(filePath) // 读取所有md文件数据 - files.forEach(file => { - let dataStr = fs.readFileSync(file.filePath, 'utf8');// 读取每个md文件的内容 + files.forEach((file) => { + let dataStr = fs.readFileSync(file.filePath, 'utf8') // 读取每个md文件的内容 const fileMatterObj = matter(dataStr) // 解析md文件的front Matter。 fileMatterObj => {content:'剔除frontmatter后的文件内容字符串', data:{}, ...} - let matterData = fileMatterObj.data; // 得到md文件的front Matter - + let matterData = fileMatterObj.data // 得到md文件的front Matter + let mark = false // 删除操作 if (config.delete) { - if( type(config.delete) !== 'array' ) { + if (type(config.delete) !== 'array') { log(chalk.yellow('未能完成删除操作,delete字段的值应该是一个数组!')) } else { - config.delete.forEach(item => { + config.delete.forEach((item) => { if (matterData[item]) { delete matterData[item] mark = true } }) - } } @@ -77,16 +78,21 @@ async function main() { Object.assign(matterData, config.data) // 将配置数据合并到front Matter对象 mark = true } - + // 有操作时才继续 if (mark) { - if(matterData.date && type(matterData.date) === 'date') { + if (matterData.date && type(matterData.date) === 'date') { matterData.date = repairDate(matterData.date) // 修复时间格式 } - const newData = jsonToYaml.stringify(matterData).replace(/\n\s{2}/g,"\n").replace(/"/g,"") + '---\r\n' + fileMatterObj.content; - fs.writeFileSync(file.filePath, newData); // 写入 + const newData = + jsonToYaml + .stringify(matterData) + .replace(/\n\s{2}/g, '\n') + .replace(/"/g, '') + + '---\r\n' + + fileMatterObj.content + fs.writeFileSync(file.filePath, newData) // 写入 log(chalk.green(`update frontmatter:${file.filePath} `)) } - }) } diff --git a/utils/modules/fn.js b/utils/modules/fn.js index 48cbbd1..8d4635b 100644 --- a/utils/modules/fn.js +++ b/utils/modules/fn.js @@ -1,21 +1,25 @@ // 类型判断 -exports.type = function (o){ +exports.type = function (o) { var s = Object.prototype.toString.call(o) return s.match(/\[object (.*?)\]/)[1].toLowerCase() } - // 修复date时区格式的问题 - exports.repairDate = function (date) { - date = new Date(date); - return `${date.getUTCFullYear()}-${zero(date.getUTCMonth()+1)}-${zero(date.getUTCDate())} ${zero(date.getUTCHours())}:${zero(date.getUTCMinutes())}:${zero(date.getUTCSeconds())}`; +// 修复date时区格式的问题 +exports.repairDate = function (date) { + date = new Date(date) + return `${date.getUTCFullYear()}-${zero(date.getUTCMonth() + 1)}-${zero(date.getUTCDate())} ${zero( + date.getUTCHours() + )}:${zero(date.getUTCMinutes())}:${zero(date.getUTCSeconds())}` } // 日期的格式 exports.dateFormat = function (date) { - return `${date.getFullYear()}-${zero(date.getMonth()+1)}-${zero(date.getDate())} ${zero(date.getHours())}:${zero(date.getMinutes())}:${zero(date.getSeconds())}` + return `${date.getFullYear()}-${zero(date.getMonth() + 1)}-${zero(date.getDate())} ${zero(date.getHours())}:${zero( + date.getMinutes() + )}:${zero(date.getSeconds())}` } // 小于10补0 -function zero(d){ - return d.toString().padStart(2,'0') -} \ No newline at end of file +function zero(d) { + return d.toString().padStart(2, '0') +} diff --git a/utils/modules/readFileList.js b/utils/modules/readFileList.js index 8eb97c6..74a4eb6 100644 --- a/utils/modules/readFileList.js +++ b/utils/modules/readFileList.js @@ -1,43 +1,49 @@ /** * 读取所有md文件数据 */ -const fs = require('fs'); // 文件模块 -const path = require('path'); // 路径模块 -const docsRoot = path.join(__dirname, '..', '..', 'docs'); // docs文件路径 +const fs = require('fs') // 文件模块 +const path = require('path') // 路径模块 +const docsRoot = path.join(__dirname, '..', '..', 'docs') // docs文件路径 function readFileList(dir = docsRoot, filesList = []) { - const files = fs.readdirSync(dir); - files.forEach( (item, index) => { - let filePath = path.join(dir, item); - const stat = fs.statSync(filePath); - if (stat.isDirectory() && item !== '.vuepress') { - readFileList(path.join(dir, item), filesList); //递归读取文件 - } else { - if(path.basename(dir) !== 'docs'){ // 过滤docs目录级下的文件 + const files = fs.readdirSync(dir) + files.forEach((item, index) => { + let filePath = path.join(dir, item) + const stat = fs.statSync(filePath) + if (stat.isDirectory() && item !== '.vuepress') { + readFileList(path.join(dir, item), filesList) //递归读取文件 + } else { + if (path.basename(dir) !== 'docs') { + // 过滤docs目录级下的文件 - const fileNameArr = path.basename(filePath).split('.') - let name = null, type = null; - if (fileNameArr.length === 2) { // 没有序号的文件 - name = fileNameArr[0] - type = fileNameArr[1] - } else if (fileNameArr.length === 3) { // 有序号的文件 - name = fileNameArr[1] - type = fileNameArr[2] - } else { // 超过两个‘.’的 - log(chalk.yellow(`warning: 该文件 "${filePath}" 没有按照约定命名,将忽略生成相应数据。`)) - return - } - if(type === 'md'){ // 过滤非md文件 - filesList.push({ - name, - filePath - }); - } + const filename = path.basename(filePath) + const fileNameArr = filename.split('.') + const firstDotIndex = filename.indexOf('.') + const lastDotIndex = filename.lastIndexOf('.') + let name = null, + type = null + if (fileNameArr.length === 2) { + // 没有序号的文件 + name = fileNameArr[0] + type = fileNameArr[1] + } else if (fileNameArr.length >= 3) { + // 有序号的文件(或文件名中间有'.') + name = filename.substring(firstDotIndex + 1, lastDotIndex) + type = filename.substring(lastDotIndex + 1) } - } - }); - return filesList; + + if (type === 'md') { + // 过滤非md文件 + filesList.push({ + name, + filePath + }) + } + } + } + }) + return filesList } -module.exports = readFileList; \ No newline at end of file +module.exports = readFileList