add 永久链接

This commit is contained in:
xugaoyi 2019-12-25 17:22:52 +08:00
parent e47e5aa8b5
commit ed0ec75b84
32 changed files with 269 additions and 115 deletions

View File

@ -1,19 +1,33 @@
module.exports = [
{text: '首页', link: '/'},
{text: '前端', link: '/01.前端/01.JavaScript/01.JavaScript中的名词概念'},
{text: '页面', link: '/02.页面/01.html-css/00.flex布局语法'},
{text: '技术杂谈', link: '/03.技术杂谈/01.技术杂谈/01.Git使用手册'},
{text: '前端', link: '/70d1485bb4e5754b/'},
{text: '页面', link: '/0a83b083bdf257cb/'},
{text: '技术杂谈', link: '/9a7ee40fc232253e/'},
{text: '其他',
items: [
{text: '学习', link: '/04.其他/01.学习/01.学习网站'},
{text: '学习笔记', link: '/04.其他/02.学习笔记/01.小程序笔记'},
{text: '面试', link: '/04.其他/03.面试/01.面试问题集锦'},
{text: '在线工具', link: '/04.其他/04.在线工具'},
{text: '友情链接', link: '/04.其他/05.友情链接'},
{text: '学习', link: '/2e9ba3fa6e1ed0e9/'},
{text: '学习笔记', link: '/236ec09c26876b59/'},
{text: '面试', link: '/aea6571b7a8bae86/'},
{text: '在线工具', link: '/9c2232288caaa8ec/'},
{text: '友情链接', link: '/844eea1b2387fb96/'},
]
},
{text: '关于我', link: '/05.关于我/01.关于我'},
{text: '关于我', link: '/6483e31017cf298b/'},
// {text: '前端', link: '/01.前端/01.JavaScript/01.JavaScript中的名词概念'},
// {text: '页面', link: '/02.页面/01.html-css/00.flex布局语法'},
// {text: '技术杂谈', link: '/03.技术杂谈/01.技术杂谈/01.Git使用手册'},
// {text: '其他',
// items: [
// {text: '学习', link: '/04.其他/01.学习/01.学习网站'},
// {text: '学习笔记', link: '/04.其他/02.学习笔记/01.小程序笔记'},
// {text: '面试', link: '/04.其他/03.面试/01.面试问题集锦'},
// {text: '在线工具', link: '/04.其他/04.在线工具'},
// {text: '友情链接', link: '/04.其他/05.友情链接'},
// ]
// },
// {text: '关于我', link: '/05.关于我/01.关于我'},
// {text: '技术杂谈',items:[
// {text: '技术',items:[

View File

@ -1,7 +1,8 @@
<!-- ---
title: 我是javascript
permalink: /javascript
--- -->
---
title: JavaScript中的名词概念
date: 2019-12-25
permalink: 70d1485bb4e5754b
---
# JavaScript中的名词概念

View File

@ -1,3 +1,8 @@
---
title: 数据类型转换
date: 2019-12-25
permalink: d039d42572a97b66
---
# 数据类型转换
## 强制(手动)转换

View File

@ -1,3 +1,8 @@
---
title: ES5面向对象
date: 2019-12-25
permalink: b1af5cb8996363c5
---
# ES5面向对象
```js

View File

@ -1,3 +1,8 @@
---
title: ES6面向对象
date: 2019-12-25
permalink: 1f4123be6f45abcd
---
# ES6面向对象
```js

View File

@ -1,3 +1,8 @@
---
title: new命令原理
date: 2019-12-25
permalink: 8143cc480faf9a11
---
# new命令原理
```js

View File

@ -1,3 +1,8 @@
---
title: 多种数组去重性能对比
date: 2019-12-25
permalink: e808fba1fa8fbab2
---
# 多种数组去重性能对比
## 测试模板

View File

@ -1,3 +1,8 @@
---
title: flex布局语法
date: 2019-12-25
permalink: 0a83b083bdf257cb
---
# flex布局语法
## 一、flex 布局是什么?

View File

@ -1,3 +1,8 @@
---
title: flex布局案例-基础
date: 2019-12-25
permalink: ea6db1530c42ad51
---
# flex布局案例-基础
先上代码,[效果](#效果)在后面

View File

@ -1,3 +1,8 @@
---
title: flex布局案例-骰子
date: 2019-12-25
permalink: eff61bc8b4f4695d
---
# flex布局案例-骰子
先上代码,[效果](#效果)在后面

View File

@ -1,3 +1,8 @@
---
title: flex布局案例-网格布局
date: 2019-12-25
permalink: 85b5a3fe218a34b7
---
# flex布局案例-网格布局
先上代码,[效果](#效果)在后面

View File

@ -1,3 +1,8 @@
---
title: flex布局案例-圣杯布局
date: 2019-12-25
permalink: df9e7c7214fa5046
---
# flex布局案例-圣杯布局
先上代码,[效果](#效果)在后面

View File

@ -1,3 +1,8 @@
---
title: flex布局案例-输入框布局
date: 2019-12-25
permalink: 05cc577fb51c7998
---
# flex布局案例-输入框布局
先上代码,[效果](#效果)在后面

View File

@ -1,3 +1,8 @@
---
title: CSS3之transform过渡
date: 2019-12-25
permalink: 02d7f59d98d87409
---
# CSS3之transform过渡
html结构

View File

@ -1,3 +1,8 @@
---
title: CSS3之animation动画
date: 2019-12-25
permalink: c2c0432138f6e042
---
# CSS3之animation动画
先上代码,[效果](#效果)在后面

View File

@ -1,3 +1,8 @@
---
title: Git使用手册
date: 2019-12-25
permalink: 9a7ee40fc232253e
---
# Git使用手册

View File

@ -1,3 +1,8 @@
---
title: GitHub高级搜索技巧
date: 2019-12-25
permalink: 4c778760be26d8b3
---
# GitHub高级搜索技巧
`in:name <关键字>`

View File

@ -1,3 +1,8 @@
---
title: Markdown使用教程
date: 2019-12-25
permalink: ad247c4332211551
---
# Markdown使用教程
## 一、Markdown

View File

@ -1,3 +1,8 @@
---
title: npm常用命令
date: 2019-12-25
permalink: 61f2f95fd7da14fd
---
# npm常用命令
## 简介

View File

@ -1,3 +1,8 @@
---
title: yaml语言教程
date: 2019-12-25
permalink: 4e8444e2d534d14f
---
# yaml语言教程
## 简介

View File

@ -1,3 +1,8 @@
---
title: 解决百度无法收录搭建在GitHub上的个人博客的问题
date: 2019-12-25
permalink: 41f87d890d0a02af
---
# 解决百度无法收录搭建在GitHub上的静态博客的问题

View File

@ -1,3 +1,8 @@
---
title: 使用Gitalk实现静态博客无后台评论系统
date: 2019-12-25
permalink: 1da0bf9a988eafe5
---
# 使用Gitalk实现静态博客无后台评论系统
## 前言

View File

@ -1,3 +1,8 @@
---
title: 学习网站
date: 2019-12-25
permalink: 2e9ba3fa6e1ed0e9
---
# 学习网站
## 文档类

View File

@ -1,3 +1,8 @@
---
title: 学习效率低,忘性很大怎么办?
date: 2019-12-25
permalink: 839158575e5c4866
---
# 学习效率低,忘性很大怎么办?
## 关于学习

View File

@ -1,3 +1,8 @@
---
title: 小程序笔记
date: 2019-12-25
permalink: 236ec09c26876b59
---
## 基础课程部分
#### 微信公众平台

View File

@ -1,3 +1,8 @@
---
title: 面试问题集锦
date: 2019-12-25
permalink: aea6571b7a8bae86
---
# 面试问题集锦
## 请做一下自我介绍

View File

@ -1,3 +1,8 @@
---
title: 在线工具
date: 2019-12-25
permalink: 9c2232288caaa8ec
---
# 在线工具

View File

@ -0,0 +1,5 @@
---
title: 友情链接
date: 2019-12-25
permalink: 844eea1b2387fb96
---

View File

@ -1,3 +1,8 @@
---
title: 关于我
date: 2019-12-25
permalink: 6483e31017cf298b
---
## 关于我
web前端工程师喜欢唱、跳、rap、篮球写程序。 本人↓↓↓

View File

@ -2,15 +2,17 @@
"name": "evanblog",
"version": "1.0.0",
"scripts": {
"dev": "node utils/sidebarAndNav.js && vuepress dev docs",
"build": "node utils/sidebarAndNav.js && vuepress build docs",
"deploy": "bash deploy.sh"
"dev": "node utils/frontmatter.js && node utils/sidebarAndNav.js && vuepress dev docs",
"build": "node utils/frontmatter.js && node utils/sidebarAndNav.js && vuepress build docs",
"deploy": "bash deploy.sh",
"updateFM": "node utils/frontmatter.js -update"
},
"license": "MIT",
"devDependencies": {
"@vuepress/plugin-back-to-top": "^1.2.0",
"@vuepress/plugin-medium-zoom": "^1.2.0",
"ejs": "^3.0.1",
"md5.js": "^1.3.5",
"tracer": "^1.0.1",
"vuepress": "^1.1.0",
"vuepress-plugin-baidu-autopush": "^1.0.1",

101
utils/frontmatter.js Normal file
View File

@ -0,0 +1,101 @@
/**
* nodejs自动生成永久链接
*/
const fs = require('fs'); // 文件模块
const path = require('path'); // 路径模块
const logger = require('tracer').colorConsole(); // 控制台工具(用于控制台打印信息包含时间、打印类型、文件及代码行号、对象、颜色)
const MD5 = require('md5.js');
const arg = process.argv.splice(2)[0]; // 获取命令行 传入参数
const docsRoot = path.join(__dirname, '..', 'docs'); // docs文件路径
main();
/**
* 主体函数
*/
function main() {
const files = readFileList(docsRoot); // 读取所有md文件
files.forEach(file => {
let dataStr = fs.readFileSync(file.filePath, 'utf8');// 读取每个md文件内容
if(dataStr.substring(0,3) !== '---'){ // 没有FrontMatter
console.log(`写入FrontMatter${file.filePath}`)
writeFrontMatter(file, dataStr);
} else { // 已有FrontMatter
if (arg !== '-update'){
return;
}
// 重新写入FrontMatter
const dataArr = dataStr.split(/\r\n|\n|\r/gm);
const fmArr = dataArr.slice(0,5);
const dataStrOld = dataArr.slice(5).join('\r\n');
// 判断FrontMatter 是否为自动生成的格式
if (fmArr[0] === '---' && /title/.test(fmArr[1]) && /date/.test(fmArr[2]) && /permalink/.test(fmArr[3]) && fmArr[4] === '---') {
console.log(`更新FrontMatter${file.filePath} `)
writeFrontMatter(file, dataStrOld);
} else {
logger.warn(`此文件FrontMatter更新失败${file.filePath}因为它的FrontMatter格式并非自动生成的。`)
}
}
})
}
// 写入FrontMatter
function writeFrontMatter(file, dataStr) {
const stat = fs.statSync(file.filePath);
const date = stat.birthtime; // 创建时间
const dateStr = `${date.getFullYear()}-${zero(date.getMonth()+1)}-${zero(date.getDate())}`;
const newData = `---\r\ntitle: ${file.name}\r\ndate: ${dateStr}\r\npermalink: ${new MD5().update(file.name).digest('hex').substring(0,16)}\r\n---\r\n` + dataStr;
fs.writeFileSync(file.filePath, newData); // 写入
}
// 补0
function zero(d){
return d.toString().padStart(2,'0')
}
// 读取所有md文件
function readFileList(dir, 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目录级下的文件
// 过滤非md文件
let [, name, type] = path.basename(filePath).split('.');
if(type === 'md'){
filesList.push({
name,
filePath
});
}
}
}
});
return filesList;
}
/**
* 读取指定目录下的文件绝对路径
* @param {String} root 指定的目录
*/
function readTocs(root){
const result = [];
const files = fs.readdirSync(root); // 方法:读取目录,返回数组成员是root底下所有的目录名 (包含文件文件夹和文件)
files.forEach(name => {
const file = path.resolve(root, name); // 方法:将路径或路径片段的序列解析为绝对路径
if (fs.statSync(file).isDirectory() && name !== '.vuepress') { // 是否为文件夹目录,并排除.vuepress文件
result.push(file);
}
})
return result;
}

View File

@ -1,99 +0,0 @@
/**
* nodejs自动生成永久链接
*/
const fs = require('fs'); // 文件模块
const path = require('path'); // 路径模块
const logger = require('tracer').colorConsole(); // 控制台工具(用于控制台打印信息包含时间、打印类型、文件及代码行号、对象、颜色)
const docsRoot = path.join(__dirname, '..', 'docs'); // docs文件路径
// 读取所有文件
function readFileList(dir, filesList = []) {
const files = fs.readdirSync(dir);
files.forEach((item, index) => {
var fullPath = path.join(dir, item);
const stat = fs.statSync(fullPath);
if (stat.isDirectory() && item !== '.vuepress') {
readFileList(path.join(dir, item), filesList); //递归读取文件
} else {
filesList.push(fullPath);
}
});
return filesList;
}
let filesList = readFileList(docsRoot);
console.log(filesList);
// main();
// /**
// * 主体函数
// */
// function main() {
// const tocs = readTocs(docsRoot); // 得到一个对路路径目录数组
// tocs.forEach(toc => { // toc为每个目录的绝对路径
// // console.log(toc)
// // E:\Github仓库集合\vuepress-Evan-blog\docs\01.前端
// // E:\Github仓库集合\vuepress-Evan-blog\docs\02.页面
// // E:\Github仓库集合\vuepress-Evan-blog\docs\03.技术杂谈
// // E:\Github仓库集合\vuepress-Evan-blog\docs\04.其他
// // E:\Github仓库集合\vuepress-Evan-blog\docs\05.关于我
// const files = fs.readdirSync(toc); // 读取目录(文件和文件夹),返回数组
// console.log(files)
// let [order, title, type] = filename.split('.');
// files.forEach(filename => {
// const file = path.resolve(toc, filename); // 方法:将路径或路径片段的序列解析为绝对路径
// const stat = fs.statSync(file); // 文件信息
// // console.log(file)
// if(stat.isDirectory()){ // 是否为文件夹目录
// } else {
// }
// })
// })
// }
/**
* 读取指定目录下的文件绝对路径
* @param {String} root 指定的目录
*/
function readTocs(root){
const result = [];
const files = fs.readdirSync(root); // 方法:读取目录,返回数组成员是root底下所有的目录名 (包含文件文件夹和文件)
files.forEach(name => {
const file = path.resolve(root, name); // 方法:将路径或路径片段的序列解析为绝对路径
if (fs.statSync(file).isDirectory() && name !== '.vuepress') { // 是否为文件夹目录,并排除.vuepress文件
result.push(file);
}
})
return result;
}