Skip to content

Commit

Permalink
feat: add website scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Dec 5, 2021
1 parent 0259e8c commit 1fe6eb1
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 0 deletions.
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "mysql-tutorial",
"version": "1.0.0",
"description": "从零开始学习MySQL,主要是面向MySQL数据库管理系统初学者。",
"homepage": "https://jaywcjlove.github.io/mysql-tutorial",
"author": "jaywcjlove",
"license": "MIT",
"private": true,
"scripts": {
"start": "node scripts/build.mjs"
},
"repository": {
"type": "git",
"url": "git+https://github.com/jaywcjlove/mysql-tutorial.git"
},
"devDependencies": {
"fs-extra": "^10.0.0",
"markdown-to-html-cli": "^3.2.4",
"recursive-readdir-files": "^2.0.7"
}
}
73 changes: 73 additions & 0 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import path from 'path';
import fs from 'fs-extra';
import getFiles from 'recursive-readdir-files';
import { create } from 'markdown-to-html-cli';
import { favicon } from './node/favicon.mjs';
import { header } from './node/header.mjs';
import { footer } from './node/footer.mjs';

const styleStr = fs.readFileSync(path.relative(process.cwd(), 'scripts/style.css'));
function createOption(editPath) {
const href = path.relative(process.cwd(), editPath);
return {
'github-corners': 'https://github.com/jaywcjlove/handbook.git',
document: {
style: [styleStr.toString()],
link: [
{ rel: 'icon', href: favicon, type: 'image/x-icon' }
// { rel: 'shortcut icon', href: './favicon.ico' },
]
},
rewrite: (node) => {
if (node.type === 'element' && node.properties.href && !node.properties['data-edit'] && /\.md(.*?)$/.test(node.properties.href)) {
if (/(readme).md$/.test(node.properties.href.toLocaleLowerCase())) {
node.properties.href = node.properties.href.replace(/(readme|README).md$/, 'index.html');
} else if (/.md$/.test(node.properties.href.toLocaleLowerCase())) {
node.properties.href = node.properties.href.replace(/.md$/, '.html');
} else {
node.properties.href = node.properties.href.replace(/.md(.*?)$/, '.html$1');;
}
}
if (node.type === 'element' && node.tagName === 'body') {
node.properties = { ...node.properties, id: 'totop' };
const homeUrl = path.relative(`${href}/..`, './index.html');
node.children = [header(homeUrl), ...node.children, footer(href)];
}
}
}
}

;(async () => {
await fs.ensureDir('build');
const files = await getFiles(process.cwd(), {
ignored: /\/(node_modules|\.git|build)/,
filter: (item) => /(.md|.svg|.jpg|.png|.mp4)$/.test(item.path)
});
await Promise.all(files.map(async (item) => {
const markdown = await fs.readFile(item.path);
const outputPath = path.join('build', path.relative(process.cwd(), item.path).replace(/(README|readme).md$/, 'index.html').replace(/.md$/, '.html'));
await fs.ensureDir(path.dirname(outputPath));
if (/.md$/.test(item.path)) {
const options = createOption(item.path);
let title = markdown.toString().match(/^([\s\S]*?)===/)
title = title ? title[1].replace(/\n/, '') : '';
const html = create({
markdown, ...options,
document: {
title: `${title ? `${title} - ` : ''}mysql-tutorial`,
...options.document,
meta: [
{ description: `${title ? `${title}。`: '' }从零开始学习MySQL,主要是面向MySQL数据库管理系统初学者。- mysql-tutorial` },
{ keywords: 'example,mysql-tutorial,mysql,tutorial' }
]
}
});
await fs.writeFile(outputPath, html);
console.log(`♻️ create file: \x1b[32;1m ${outputPath} \x1b[0m`);
} else {
await fs.copyFile(item.path, outputPath);
console.log(`🏞 copied file: \x1b[32;1m ${outputPath} \x1b[0m`);
}

}));
})();
1 change: 1 addition & 0 deletions scripts/node/favicon.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const favicon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAAEIlJREFUeF7tnXtwVNUdx3/n7kIe8sgTNEjLTMeAUrVUKB0U0f6D1ZkKCqhBJKDSdjplHEnW6B8l0hZIQKBaq+KMQDvTOhYfnY5jpU7rg9pp0Y5aSysKA4SEAJJNIJjdkN3TOWuigcnuub97727u2fu9MzuJ7ve8vt/72XPP2XCvIBxwAA6kdUDAGzgAB9I7AEB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4PtAMAJNDxY/A6BwCIziG8H2gH/g8LPRyq8vuk8QAAAABJRU5ErkJggg=='
60 changes: 60 additions & 0 deletions scripts/node/footer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

export const footer = (editPath) => {
return {
type: 'element',
tagName: 'div',
properties: {
className: 'footer',
},
children: [
{
type: 'element',
tagName: 'a',
properties: {
'data-edit': true,
target: '__blank',
title: `https://github.com/jaywcjlove/handbook/edit/master/${editPath}`,
href: `https://github.com/jaywcjlove/handbook/edit/master/${editPath}`,
},
children: [ { type: 'text', value: '编辑当前页面' } ]
},
{
type: 'element',
tagName: 'a',
properties: {
target: '__blank',
href: 'https://jaywcjlove.gitee.io/handbook/',
},
children: [ { type: 'text', value: '国内镜像站点 🇨🇳' } ]
},
{
type: 'element',
tagName: 'a',
properties: {
target: '__blank',
href: 'https://github.com/jaywcjlove/handbook',
},
children: [ { type: 'text', value: 'Github' } ]
},
{
type: 'element',
tagName: 'a',
properties: {
target: '__blank',
href: 'https://gitee.com/jaywcjlove/handbook',
},
children: [ { type: 'text', value: 'Gitee' } ]
},
{
type: 'element',
tagName: 'div',
properties: {
className: 'copyright',
},
children: [
{ type: 'text', value: 'Copyright © 2021. All rights reserved.' }
]
}
]
}
}
55 changes: 55 additions & 0 deletions scripts/node/header.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { favicon } from './favicon.mjs';

export const header = (homeUrl) => {
return {
type: 'element',
tagName: 'header',
properties: { className: 'header', },
children: [
{
type: 'element',
tagName: 'article',
properties: { className: 'inner', },
children: [
{
type: 'element',
tagName: 'a',
properties: {
className: 'logo',
href: homeUrl || 'https://jaywcjlove.github.io/mysql-tutorial',
},
children: [
{
type: 'element',
tagName: 'img',
properties: {
src: favicon,
alt: 'mysql-tutorial logo',
},
children: []
}
]
}, {
type: 'element',
tagName: 'div',
properties: {
className: 'title',
},
children: [
{ type: 'text', value: 'mysql-tutorial' }
]
}, {
type: 'element',
tagName: 'nav',
properties: {
className: 'nav',
},
children: [

]
}
]
}
]
}
}
67 changes: 67 additions & 0 deletions scripts/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
.header {
position: fixed;
width: 100%;
background: #fff;
backdrop-filter: saturate(180%) blur(0.4rem);
background-color: rgba(255,255,255,0.55);
border-bottom: 1px solid #00000014;
z-index: 99;
top: 0;
}

.header .inner {
max-width: 960px;
margin: 0 auto;
display: flex;
justify-content: space-between;
padding: 5px 0;
}

.header .logo {
margin-right: 10px;
}
.header .title {
display: flex;
align-items: center;
font-size: 16px;
font-weight: bold;
color: #333;
}
.header .logo img {
height: 26px;
display: block;
}

.markdown-body {
margin-top: 78px;
}

.footer {
max-width: 960px;
margin: 0 auto;
text-align: center;
padding: 0 0 110px 0;
border-top: 1px solid hsla(210,18%,87%,1);
padding-top: 18px;
}

.footer a {
font-size: 14px;
text-decoration: initial;
color: #3f51b5;
}

.footer a:hover {
color:#009688;
text-decoration: underline;
}

.footer a + a {
margin-left: 10px;
}

.footer .copyright {
color: #596068;
font-size: 14px;
padding-top: 5px;
}

0 comments on commit 1fe6eb1

Please sign in to comment.