Skip to content

Commit

Permalink
使用新的 PWA 资源生成工具
Browse files Browse the repository at this point in the history
  • Loading branch information
Big-Cake-jpg committed May 2, 2024
1 parent 0106b07 commit 5bd69ac
Show file tree
Hide file tree
Showing 6 changed files with 553 additions and 96 deletions.
53 changes: 29 additions & 24 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import { fileURLToPath } from "node:url"
import { defineConfig } from "vitepress"
import type { DefaultTheme } from "vitepress/theme"
import { withPwa, type PwaOptions } from "@vite-pwa/vitepress"
import { cwd } from 'node:process'
import { BiDirectionalLinks } from '@nolebase/markdown-it-bi-directional-links'
import {
InlineLinkPreviewElementTransform
} from '@nolebase/vitepress-plugin-inline-link-preview/markdown-it'
import { BiDirectionalLinks } from "@nolebase/markdown-it-bi-directional-links"
import { InlineLinkPreviewElementTransform } from "@nolebase/vitepress-plugin-inline-link-preview/markdown-it"
import {
GitChangelog,
GitChangelogMarkdownSection,
} from '@nolebase/vitepress-plugin-git-changelog/vite'
} from "@nolebase/vitepress-plugin-git-changelog/vite"

const COMMIT_ID = process.env.COMMIT_REF || process.env.GITHUB_SHA || process.env.CF_PAGES_COMMIT_SHA || "local"
const COMMIT_ID =
process.env.COMMIT_REF ||
process.env.GITHUB_SHA ||
process.env.CF_PAGES_COMMIT_SHA ||
"local"
const commitRef = COMMIT_ID?.slice(0, 8)
const environment = process.env.DEPLOYMENT_STATUS || process.env.NODE_ENV
const environment =
process.env.DEPLOYMENT_STATUS || process.env.NODE_ENV || "development"
const pwaName = process.env.PWA_NAME || "CrashMC 文档(本地)"

const viteConfig = {
Expand All @@ -28,36 +30,34 @@ const viteConfig = {
include: [
// @rive-app/canvas is a CJS/UMD module, so it needs to be included here
// for Vite to properly bundle it.
'@nolebase/vitepress-plugin-enhanced-readabilities > @nolebase/ui > @rive-app/canvas',
],
exclude: [
'@nolebase/vitepress-plugin-enhanced-readabilities/client',
"@nolebase/vitepress-plugin-enhanced-readabilities > @nolebase/ui > @rive-app/canvas",
],
exclude: ["@nolebase/vitepress-plugin-enhanced-readabilities/client"],
},
ssr: {
noExternal: [
// 如果还有别的依赖需要添加的话,并排填写和配置到这里即可
'@nolebase/vitepress-plugin-enhanced-readabilities',
'@nolebase/vitepress-plugin-inline-link-preview',
"@nolebase/vitepress-plugin-enhanced-readabilities",
"@nolebase/vitepress-plugin-inline-link-preview",
],
},
plugins: [
GitChangelog({
// 填写在此处填写您的仓库链接
repoURL: () => 'https://github.com/GlobeMC/crashmc.com',
repoURL: () => "https://github.com/GlobeMC/crashmc.com",
rewritePaths: {
'docs/': '',
"docs/": "",
},
}),
GitChangelogMarkdownSection({
locales: {
gitChangelogMarkdownSectionTitles: {
changelog: '文件历史',
contributors: '贡献者',
changelog: "文件历史",
contributors: "贡献者",
},
},
}),
]
],
}

const pwaConfig: PwaOptions = {
Expand Down Expand Up @@ -149,6 +149,11 @@ const pwaConfig: PwaOptions = {
},
],
},
pwaAssets: {
config: true,
overrideManifestIcons: true,
injectThemeColor: true,
},
}

const themeConfig: DefaultTheme.Config = {
Expand Down Expand Up @@ -291,7 +296,7 @@ const themeConfig: DefaultTheme.Config = {

sidebarMenuLabel: "菜单",
returnToTopLabel: "返回顶部",
externalLinkIcon: true,
externalLinkIcon: false,
darkModeSwitchLabel: "外观",
lightModeSwitchTitle: "切换到浅色模式",
darkModeSwitchTitle: "切换到深色模式",
Expand Down Expand Up @@ -319,9 +324,10 @@ export default withPwa(
config: (md) => {
// @ts-expect-error TS2769
md.use(BiDirectionalLinks({
dir: "docs",
baseDir: "/",
})),
dir: "docs",
baseDir: "/",
}),
),
// @ts-expect-error TS2769
md.use(InlineLinkPreviewElementTransform)
},
Expand All @@ -332,7 +338,6 @@ export default withPwa(
},

head: [
["link", { rel: "icon", href: "/logo-brand.webp" }],
[
"script",
{
Expand Down
128 changes: 62 additions & 66 deletions .vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { h } from "vue"

// Components
import LauncherBadge from "./global-components/LauncherBadge.vue"
import Contributors from "./components/Contributors.vue"
import ReloadPrompt from "./components/ReloadPrompt.vue"

// Plugins
Expand All @@ -18,28 +17,24 @@ import vitepressBackToTop from "vitepress-plugin-back-to-top"
import {
NolebaseEnhancedReadabilitiesMenu,
NolebaseEnhancedReadabilitiesScreenMenu,
} from '@nolebase/vitepress-plugin-enhanced-readabilities/client'
import {
NolebaseInlineLinkPreviewPlugin,
} from '@nolebase/vitepress-plugin-inline-link-preview/client'
import { InjectionKey } from '@nolebase/vitepress-plugin-git-changelog/client'
import '@nolebase/vitepress-plugin-inline-link-preview/client/style.css'
import {
NolebaseGitChangelogPlugin
} from '@nolebase/vitepress-plugin-git-changelog/client'
} from "@nolebase/vitepress-plugin-enhanced-readabilities/client"
import { NolebaseInlineLinkPreviewPlugin } from "@nolebase/vitepress-plugin-inline-link-preview/client"
import { InjectionKey } from "@nolebase/vitepress-plugin-git-changelog/client"
import "@nolebase/vitepress-plugin-inline-link-preview/client/style.css"
import { NolebaseGitChangelogPlugin } from "@nolebase/vitepress-plugin-git-changelog/client"

import '@nolebase/vitepress-plugin-git-changelog/client/style.css'
import "@nolebase/vitepress-plugin-git-changelog/client/style.css"

// Styles
import "./style.css"
import "vitepress-plugin-back-to-top/dist/style.css"
import "vitepress-plugin-codeblocks-fold/style/index.scss"
import "@andatoshiki/vitepress-plugin-nprogress/lib/css/index.css"
import "viewerjs/dist/viewer.min.css"
import '@nolebase/vitepress-plugin-enhanced-readabilities/client/style.css'
import "@nolebase/vitepress-plugin-enhanced-readabilities/client/style.css"

function generateAvatarUrl(username: string) {
return `https://cdn.crashmc.com/https://github.com/${username}.png`;
return `https://cdn.crashmc.com/https://github.com/${username}.png`
}

export default {
Expand All @@ -49,9 +44,10 @@ export default {
// https://vitepress.dev/guide/extending-default-theme#layout-slots
"layout-bottom": () => h(ReloadPrompt),
// 为较宽的屏幕的导航栏添加阅读增强菜单
'nav-bar-content-after': () => h(NolebaseEnhancedReadabilitiesMenu),
"nav-bar-content-after": () => h(NolebaseEnhancedReadabilitiesMenu),
// 为较窄的屏幕(通常是小于 iPad Mini)添加阅读增强菜单
'nav-screen-content-after': () => h(NolebaseEnhancedReadabilitiesScreenMenu),
"nav-screen-content-after": () =>
h(NolebaseEnhancedReadabilitiesScreenMenu),
})
},
enhanceApp(ctx: EnhanceAppContext) {
Expand All @@ -67,89 +63,89 @@ export default {
ctx.app.provide(InjectionKey, {
mapContributors: [
{
name: 'Big_Cake',
nameAliases: ['Big-Cake-jpg', 'Big_Cake'],
avatar: generateAvatarUrl('Big-Cake-jpg'),
name: "Big_Cake",
nameAliases: ["Big-Cake-jpg", "Big_Cake"],
avatar: generateAvatarUrl("Big-Cake-jpg"),
},
{
name: 'bingling_sama',
nameAliases: ['bingling-sama', 'bingling_sama'],
avatar: generateAvatarUrl('bingling-sama'),
name: "bingling_sama",
nameAliases: ["bingling-sama", "bingling_sama"],
avatar: generateAvatarUrl("bingling-sama"),
},
{
name: '柚子柚子',
nameAliases: ['youzi-2333', '柚子柚子'],
avatar: generateAvatarUrl('youzi-2333'),
name: "柚子柚子",
nameAliases: ["youzi-2333", "柚子柚子"],
avatar: generateAvatarUrl("youzi-2333"),
},
{
name: 'Pigeon0v0',
nameAliases: ['bwtx2023', 'bwtx1981', 'Yousa Ling', 'Pigeon0v0'],
avatar: generateAvatarUrl('Pigeon0v0'),
name: "Pigeon0v0",
nameAliases: ["bwtx2023", "bwtx1981", "Yousa Ling", "Pigeon0v0"],
avatar: generateAvatarUrl("Pigeon0v0"),
},
{
name: '233355607',
nameAliases: ['2623684696', '233355607'],
avatar: generateAvatarUrl('2623684696'),
name: "233355607",
nameAliases: ["2623684696", "233355607"],
avatar: generateAvatarUrl("2623684696"),
},
{
name: 'hejiehao',
nameAliases: ['何杰豪', 'hejiehao'],
avatar: generateAvatarUrl('hejiehao'),
name: "hejiehao",
nameAliases: ["何杰豪", "hejiehao"],
avatar: generateAvatarUrl("hejiehao"),
},
{
name: 'Rovniced',
nameAliases: ['Rovniced', 'Enlysure'],
avatar: generateAvatarUrl('Rovniced'),
name: "Rovniced",
nameAliases: ["Rovniced", "Enlysure"],
avatar: generateAvatarUrl("Rovniced"),
},
{
name: 'zyxkad',
nameAliases: ['zyxkad', 'Kevin Z'],
avatar: generateAvatarUrl('zyxkad'),
name: "zyxkad",
nameAliases: ["zyxkad", "Kevin Z"],
avatar: generateAvatarUrl("zyxkad"),
},
{
name: 'HRxiaohu',
nameAliases: ['HRxiaohu'],
avatar: generateAvatarUrl('HRxiaohu'),
name: "HRxiaohu",
nameAliases: ["HRxiaohu"],
avatar: generateAvatarUrl("HRxiaohu"),
},
{
name: 'Pysio',
nameAliases: ['pysio2007', 'Pysio'],
avatar: generateAvatarUrl('pysio2007'),
name: "Pysio",
nameAliases: ["pysio2007", "Pysio"],
avatar: generateAvatarUrl("pysio2007"),
},
{
name: 'XieXiLin',
nameAliases: ['XieXiLin', 'XieXiLin2'],
avatar: generateAvatarUrl('XieXiLin2'),
name: "XieXiLin",
nameAliases: ["XieXiLin", "XieXiLin2"],
avatar: generateAvatarUrl("XieXiLin2"),
},
{
name: 'Z_Tsin',
nameAliases: ['Z_Tsin', 'ztsinsun'],
avatar: generateAvatarUrl('ztsinsun'),
name: "Z_Tsin",
nameAliases: ["Z_Tsin", "ztsinsun"],
avatar: generateAvatarUrl("ztsinsun"),
},
{
name: '9Bakabaka',
nameAliases: ['9Bakabaka'],
avatar: generateAvatarUrl('9Bakabaka'),
name: "9Bakabaka",
nameAliases: ["9Bakabaka"],
avatar: generateAvatarUrl("9Bakabaka"),
},
{
name: 'ZhuRuoLing',
nameAliases: ['ZhuRuoLing'],
avatar: generateAvatarUrl('ZhuRuoLing'),
name: "ZhuRuoLing",
nameAliases: ["ZhuRuoLing"],
avatar: generateAvatarUrl("ZhuRuoLing"),
},
{
name: 'bingxin666',
nameAliases: ['bingxin666'],
avatar: generateAvatarUrl('bingxin666'),
name: "bingxin666",
nameAliases: ["bingxin666"],
avatar: generateAvatarUrl("bingxin666"),
},
{
name: 'zkitefly',
nameAliases: ['zkitefly'],
avatar: generateAvatarUrl('zkitefly'),
name: "zkitefly",
nameAliases: ["zkitefly"],
avatar: generateAvatarUrl("zkitefly"),
},
{
name: '思遥方',
nameAliases: ['Seayay', '思遥方'],
avatar: generateAvatarUrl('Seayay'),
name: "思遥方",
nameAliases: ["Seayay", "思遥方"],
avatar: generateAvatarUrl("Seayay"),
},
],
})
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@nolebase/vitepress-plugin-inline-link-preview": "2.0.0-rc10",
"@types/pako": "^2.0.3",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@vite-pwa/assets-generator": "^0.2.4",
"@vite-pwa/vitepress": "^0.4.0",
"@vue/tsconfig": "^0.5.1",
"eslint": "^8.57.0",
Expand Down
Loading

0 comments on commit 5bd69ac

Please sign in to comment.