Skip to content

Commit

Permalink
Merge pull request #14 from hacxy/13-hacxy
Browse files Browse the repository at this point in the history
13 hacxy
  • Loading branch information
hacxy authored Jan 8, 2025
2 parents 920c394 + 5879af3 commit a216792
Show file tree
Hide file tree
Showing 33 changed files with 846 additions and 96 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/create-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"type": "module",
"version": "0.0.9",
"description": "Create vitepress mild theme.",
"author": "",
"author": {
"name": "hacxy",
"email": "[email protected]"
},
"license": "MIT",
"keywords": [
"cli",
Expand Down Expand Up @@ -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",
Expand Down
116 changes: 116 additions & 0 deletions packages/create-theme/scripts/release.js
Original file line number Diff line number Diff line change
@@ -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));
2 changes: 1 addition & 1 deletion packages/demo/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfigWithTheme<ThemeConfig>({
logo: '/cat-typing.gif',
nav: [
{ text: 'Home', link: '/' },
{ text: 'Tags', link: '/pages/tags' }
{ text: 'Tags', link: '/pages/tagsasd' }
],
sidebar: {
'/posts/orange/': 'auto',
Expand Down
12 changes: 12 additions & 0 deletions packages/demo/.vitepress/theme/Layout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!--.vitepress/theme/MyLayout.vue-->
<script setup>
import {Layout} from 'vitepress-theme-mild'
</script>

<template>
<Layout>
<template #not-found>
My custom sidebar top content
</template>
</Layout>
</template>
6 changes: 5 additions & 1 deletion packages/demo/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import MildTheme from 'vitepress-theme-mild';
import Layout from './Layout.vue';

export default MildTheme;
export default {
extends: MildTheme,
Layout
};
2 changes: 1 addition & 1 deletion packages/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default defineConfigWithTheme<ThemeConfig>({
nav: [
{
text: '指南',
link: '/guide/introduction/',
link: '/guide/intro/',
activeMatch: '/guide/'
}
],
Expand Down
Empty file added packages/docs/CHANGELOG.md
Empty file.
3 changes: 0 additions & 3 deletions packages/docs/guide/blog/frontmatter.md

This file was deleted.

9 changes: 0 additions & 9 deletions packages/docs/guide/blog/index.md

This file was deleted.

File renamed without changes.
30 changes: 30 additions & 0 deletions packages/docs/guide/intro/index.md
Original file line number Diff line number Diff line change
@@ -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)
File renamed without changes.
26 changes: 0 additions & 26 deletions packages/docs/guide/introduction/index.md

This file was deleted.

1 change: 1 addition & 0 deletions packages/docs/guide/layout/blog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 博客页布局
1 change: 1 addition & 0 deletions packages/docs/guide/layout/doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 文档页布局
6 changes: 6 additions & 0 deletions packages/docs/guide/layout/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
sidebar:
title: 布局
---

# 概述
1 change: 1 addition & 0 deletions packages/docs/guide/layout/tag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 标签页布局
41 changes: 36 additions & 5 deletions packages/docs/guide/sidebar/index.md
Original file line number Diff line number Diff line change
@@ -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'
}
}
};
```
3 changes: 0 additions & 3 deletions packages/docs/guide/tag/frontmatter.md

This file was deleted.

9 changes: 0 additions & 9 deletions packages/docs/guide/tag/index.md

This file was deleted.

4 changes: 2 additions & 2 deletions packages/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---

<style>
Expand Down
Loading

0 comments on commit a216792

Please sign in to comment.