diff --git a/README.md b/README.md index c447be5..12cace6 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,10 @@ bun create mild-theme - [hacxy.cn](https://hacxy.cn) +## Changelog + +[CHANGELOG](./packages/docs/CHANGELOG.md) + ## License [MIT](./LICENSE) License © 2023-PRESENT [Hacxy](https://github.com/hacxy) diff --git a/package.json b/package.json index 66c4f93..cfcb633 100644 --- a/package.json +++ b/package.json @@ -29,9 +29,14 @@ "devDependencies": { "@hacxy/eslint-config": "^0.0.6", "commitizen": "^4.3.1", + "conventional-changelog-cli": "^5.0.0", "cz-git": "^1.11.0", "eslint": "^9.17.0", + "execa": "^9.5.2", "lint-staged": "^15.2.11", + "picocolors": "^1.1.1", + "prompts": "^2.4.2", + "semver": "^7.6.3", "simple-git-hooks": "^2.11.1", "typescript": "^5.3.3" }, diff --git a/packages/create-theme/package.json b/packages/create-theme/package.json index 5bc07e6..ff11886 100644 --- a/packages/create-theme/package.json +++ b/packages/create-theme/package.json @@ -3,7 +3,10 @@ "type": "module", "version": "0.0.9", "description": "Create vitepress mild theme.", - "author": "", + "author": { + "name": "hacxy", + "email": "hacxy.js@outlook.com" + }, "license": "MIT", "keywords": [ "cli", @@ -32,7 +35,7 @@ "lint": "eslint .", "lint:fix": "eslint . --fix", "prepublishOnly": "npm run build", - "release": "bumpp && pnpm publish --no-git-checks" + "release": "npm run scripts/release.js" }, "dependencies": { "@inquirer/prompts": "^7.2.1", diff --git a/packages/create-theme/scripts/release.js b/packages/create-theme/scripts/release.js new file mode 100644 index 0000000..4a0e8ad --- /dev/null +++ b/packages/create-theme/scripts/release.js @@ -0,0 +1,116 @@ +import { readFileSync, writeFileSync } from 'node:fs'; +import { createRequire } from 'node:module'; +import { resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { execa } from 'execa'; +import c from 'picocolors'; +import prompts from 'prompts'; +import semver from 'semver'; + +const { version: currentVersion } = createRequire(import.meta.url)( + '../package.json' +); +const { inc: _inc, valid } = semver; + +const versionIncrements = ['patch', 'minor', 'major']; + +const tags = ['latest', 'next']; + +const dir = fileURLToPath(new URL('.', import.meta.url)); +const inc = i => _inc(currentVersion, i); +function run(bin, args, opts = {}) { + return execa(bin, args, { stdio: 'inherit', ...opts }); +} +const step = msg => console.log(c.cyan(msg)); + +async function main() { + let targetVersion; + + const versions = versionIncrements + .map(i => `${i} (${inc(i)})`) + .concat(['custom']); + + const { release } = await prompts({ + type: 'select', + name: 'release', + message: 'Select release type', + choices: versions + }); + + if (release === 3) { + targetVersion = ( + await prompts({ + type: 'text', + name: 'version', + message: 'Input custom version', + initial: currentVersion + }) + ).version; + } + else { + targetVersion = versions[release].match(/\((.*)\)/)[1]; + } + + if (!valid(targetVersion)) { + throw new Error(`Invalid target version: ${targetVersion}`); + } + + const { tag } = await prompts({ + type: 'select', + name: 'tag', + message: 'Select tag type', + choices: tags + }); + + const { yes: tagOk } = await prompts({ + type: 'confirm', + name: 'yes', + message: `Releasing v${targetVersion} on ${tags[tag]}. Confirm?` + }); + + if (!tagOk) { + return; + } + + // Update the package version. + step('\nUpdating the package version...'); + updatePackage(targetVersion); + + // sync template + step('\nSync template'); + await run('pnpm', ['sync']); + + // Build the package. + step('\nBuilding the package...'); + await run('pnpm', ['build']); + + // Commit changes to the Git and create a tag. + step('\nCommitting changes...'); + await run('git', ['add', 'package.json', '../template']); + await run('git', ['commit', '-m', `chore: release: v${targetVersion}`]); + + // Publish the package. + step('\nPublishing the package...'); + await run('pnpm', [ + 'publish', + '--tag', + tags[tag], + '--ignore-scripts', + '--no-git-checks' + ]); + + // Push. + step('\nPushing...'); + await run('git', ['push']); +} + +function updatePackage(version) { + const pkgPath = resolve(resolve(dir, '..'), 'package.json'); + const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')); + + pkg.version = version; + + writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`); +} + +main().catch(err => console.error(err)); diff --git a/packages/demo/.vitepress/config.ts b/packages/demo/.vitepress/config.ts index d9c2358..df18195 100644 --- a/packages/demo/.vitepress/config.ts +++ b/packages/demo/.vitepress/config.ts @@ -10,7 +10,7 @@ export default defineConfigWithTheme({ logo: '/cat-typing.gif', nav: [ { text: 'Home', link: '/' }, - { text: 'Tags', link: '/pages/tags' } + { text: 'Tags', link: '/pages/tagsasd' } ], sidebar: { '/posts/orange/': 'auto', diff --git a/packages/demo/.vitepress/theme/Layout.vue b/packages/demo/.vitepress/theme/Layout.vue new file mode 100644 index 0000000..cfe0427 --- /dev/null +++ b/packages/demo/.vitepress/theme/Layout.vue @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/packages/demo/.vitepress/theme/index.ts b/packages/demo/.vitepress/theme/index.ts index 044ba76..c9953b3 100644 --- a/packages/demo/.vitepress/theme/index.ts +++ b/packages/demo/.vitepress/theme/index.ts @@ -1,3 +1,7 @@ import MildTheme from 'vitepress-theme-mild'; +import Layout from './Layout.vue'; -export default MildTheme; +export default { + extends: MildTheme, + Layout +}; diff --git a/packages/docs/.vitepress/config.ts b/packages/docs/.vitepress/config.ts index dbaab53..4aece01 100644 --- a/packages/docs/.vitepress/config.ts +++ b/packages/docs/.vitepress/config.ts @@ -24,7 +24,7 @@ export default defineConfigWithTheme({ nav: [ { text: '指南', - link: '/guide/introduction/', + link: '/guide/intro/', activeMatch: '/guide/' } ], diff --git a/packages/docs/CHANGELOG.md b/packages/docs/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/packages/docs/guide/blog/frontmatter.md b/packages/docs/guide/blog/frontmatter.md deleted file mode 100644 index 4b9cab1..0000000 --- a/packages/docs/guide/blog/frontmatter.md +++ /dev/null @@ -1,3 +0,0 @@ -# frontmatter - -待补充 diff --git a/packages/docs/guide/blog/index.md b/packages/docs/guide/blog/index.md deleted file mode 100644 index 3c12c04..0000000 --- a/packages/docs/guide/blog/index.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -sidebar: - order: 7 - title: 博客布局 ---- - -# 博客页 - -待补充 diff --git a/packages/docs/guide/introduction/deploy.md b/packages/docs/guide/intro/deploy.md similarity index 100% rename from packages/docs/guide/introduction/deploy.md rename to packages/docs/guide/intro/deploy.md diff --git a/packages/docs/guide/intro/index.md b/packages/docs/guide/intro/index.md new file mode 100644 index 0000000..f340276 --- /dev/null +++ b/packages/docs/guide/intro/index.md @@ -0,0 +1,30 @@ +--- +sidebar: + order: 9 + title: 简介 + text: 概述 +--- + +# 概述 + +`VitePress Theme Mild` 以下简称(Mild Theme), 是一个且具备丰富能力的 VitePress 主题, 它基于默认主题开发, 保留了原有的默认主题的配置规则, 并在此基础上进行扩展, 加入了更多可自定义的配置项, 以及丰富的markdown能力, 并额外提供了更多布局, 例如: blog, 可以帮助你快速搭建个人博客或者技术文档. + +## 为什么开发这个主题 + +[开发VitePress主题的初衷](https://hacxy.cn/docs/posts/dev-vitepress-theme/1.start.html) + +## 案例 + +以下是正在使用这个主题的项目 + +**博客案例:** + +- [hacxy.cn](https://hacxy.cn) + +**文档案例** + +- [vitepress-theme-mild](https://theme.hacxy.cn) + +## 快速开始 + +[下一章: 快速开始](./quick-start.md) diff --git a/packages/docs/guide/introduction/quick-start.md b/packages/docs/guide/intro/quick-start.md similarity index 100% rename from packages/docs/guide/introduction/quick-start.md rename to packages/docs/guide/intro/quick-start.md diff --git a/packages/docs/guide/introduction/index.md b/packages/docs/guide/introduction/index.md deleted file mode 100644 index 63e3e2f..0000000 --- a/packages/docs/guide/introduction/index.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -sidebar: - order: 9 - title: 简介 - text: 概述 ---- - -# 概述 - -`VitePress Theme Mild` 是一个使用简单且具备丰富能力的 VitePress 主题, 它基于默认主题开发, 并额外提供了博客布局, 帮助你快速搭建个人博客或者技术文档. - -## 为什么开发这个主题 - -[开发VitePress主题的初衷](https://hacxy.cn/docs/posts/dev-vitepress-theme/1.start.html) - -## 案例 - -以下是正在使用这个主题的项目 - -**博客案例:** - -- [hacxy.cn](https://hacxy.cn) - -**文档案例** - -- [vitepress-theme-mild](https://theme.hacxy.cn) diff --git a/packages/docs/guide/layout/blog.md b/packages/docs/guide/layout/blog.md new file mode 100644 index 0000000..0b874b5 --- /dev/null +++ b/packages/docs/guide/layout/blog.md @@ -0,0 +1 @@ +# 博客页布局 diff --git a/packages/docs/guide/layout/doc.md b/packages/docs/guide/layout/doc.md new file mode 100644 index 0000000..9261478 --- /dev/null +++ b/packages/docs/guide/layout/doc.md @@ -0,0 +1 @@ +# 文档页布局 diff --git a/packages/docs/guide/layout/index.md b/packages/docs/guide/layout/index.md new file mode 100644 index 0000000..6a2648c --- /dev/null +++ b/packages/docs/guide/layout/index.md @@ -0,0 +1,6 @@ +--- +sidebar: + title: 布局 +--- + +# 概述 diff --git a/packages/docs/guide/layout/tag.md b/packages/docs/guide/layout/tag.md new file mode 100644 index 0000000..3ce0a4b --- /dev/null +++ b/packages/docs/guide/layout/tag.md @@ -0,0 +1 @@ +# 标签页布局 diff --git a/packages/docs/guide/sidebar/index.md b/packages/docs/guide/sidebar/index.md index 8d71e00..e89915d 100644 --- a/packages/docs/guide/sidebar/index.md +++ b/packages/docs/guide/sidebar/index.md @@ -1,9 +1,40 @@ --- -sidebar: - title: 侧边栏 - order: 8 +sidebar: false --- -# 介绍 +# 概述 -待补充 +`Mild Theme` 基于默认主题扩展了一项非常实用的能力, 它由默认主题提供的 [sidebar 配置](https://vitepress.dev/zh/reference/default-theme-sidebar) 所 "进化" 而来, 保留了原有的配置规则, 并提供了一个自动扫描文件路径生成侧边栏的选项. + +## 自动侧边栏 + +自动侧边栏基于多侧边栏实现, 可以根据不同的页面路径来显示不同的侧边栏, 例如: 希望在文档中创建单独的侧边栏,例如“指南”页面和“配置参考”页面。 + +为此,首先将你的页面组织到每个所需部分的目录中: + +``` +. +├─ guide/ +│ ├─ index.md +│ ├─ one.md +│ └─ two.md +└─ config/ + ├─ index.md + ├─ three.md + └─ four.md +``` + +然后,更新配置以定义每个部分的侧边栏。你可以使用默认的方式传递一个对象, 对象的key必须是从vitepress根路径开始的绝对文件路径, 它必须以`/`做结尾, 这点和默认主题的sidebar多侧边栏配置相同, 不同的是对象的值, 除了可以传递一个数组之外, 还可以使用`"auto"`,这意味着主题会扫描这个路径下所有的`.md`文件, 并自动生成侧边栏. + +```js +export default { + themeConfig: { + sidebar: { + // 当用户位于 `guide` 目录时,会显示此侧边栏 + '/guide/': 'auto', + // 当用户位于 `config` 目录时,会显示此侧边栏 + '/config/': 'auto' + } + } +}; +``` diff --git a/packages/docs/guide/tag/frontmatter.md b/packages/docs/guide/tag/frontmatter.md deleted file mode 100644 index 4b9cab1..0000000 --- a/packages/docs/guide/tag/frontmatter.md +++ /dev/null @@ -1,3 +0,0 @@ -# frontmatter - -待补充 diff --git a/packages/docs/guide/tag/index.md b/packages/docs/guide/tag/index.md deleted file mode 100644 index 1e52c81..0000000 --- a/packages/docs/guide/tag/index.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -sidebar: - title: 标签布局 - ---- - -# 标签页 - -待补充 diff --git a/packages/docs/index.md b/packages/docs/index.md index 75dc4f5..c6079c4 100644 --- a/packages/docs/index.md +++ b/packages/docs/index.md @@ -24,10 +24,10 @@ hero: actions: - theme: brand text: 介绍 - link: /guide/introduction/ + link: /guide/intro/ - theme: brand text: 快速开始 - link: /guide/introduction/quick-start + link: /guide/intro/quick-start ---