Skip to content

Commit

Permalink
update vuepress to rc
Browse files Browse the repository at this point in the history
  • Loading branch information
DerZade committed Oct 6, 2024
1 parent a96292a commit 3329592
Show file tree
Hide file tree
Showing 19 changed files with 6,010 additions and 10,442 deletions.
81 changes: 60 additions & 21 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,60 @@
name: Build and deploy

on: [push]

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: 'Checkout the source code from GitHub'
uses: actions/checkout@master
- name: Install dependencies
run: npm ci
- name: Build
run: npm run-script docs:build
- name: Deploy
if: ${{ github.ref == 'refs/heads/master' }}
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
cname: wiki.gruppe-adler.de
publish_dir: ./dist
name: Deploy to GitHub Pages

on:
push:
branches: [master]
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: pages
cancel-in-progress: false

jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Not needed if lastUpdated is not enabled

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Install dependencies
run: npm ci

- name: Build
run: npm run docs:build

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vuepress/dist

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules/
.vscode
dist/
.temp
.cache
docs/.vuepress/dist/
docs/.vuepress/.temp
docs/.vuepress/.cache
112 changes: 68 additions & 44 deletions docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
import { path, fs } from '@vuepress/utils';
import { path, fs, getDirname } from '@vuepress/utils';
import type { SidebarItemOptions } from '@vuepress/theme-default';
import { defineUserConfig } from '@vuepress/cli';
import { viteBundler } from '@vuepress/bundler-vite';
import { pwaPlugin } from '@vuepress/plugin-pwa';
import { searchPlugin } from '@vuepress/plugin-search';
import { googleAnalyticsPlugin } from '@vuepress/plugin-google-analytics';
import wikiIndexPlugin from './plugins/wiki-index';
import redirectFromDePlugin from './plugins/redirect-from-de';
import resolveImageAliasesPlugin from './plugins/resolve-images-aliases';
import { gruppeAdlerTheme } from './theme';

import type { SidebarItem } from '@vuepress/theme-default';
import type { AppOptions, DefaultThemeOptions, ViteBundlerOptions } from 'vuepress';
import type { PwaPopupPluginOptions } from '@vuepress/plugin-pwa-popup';
import type { SearchPluginOptions } from '@vuepress/plugin-search';
import type { GoogleAnalyticsPluginOptions } from '@vuepress/plugin-google-analytics';
const __dirname = getDirname(import.meta.url);

const CATEGORIES: Array<[string, string]> = [
['Bastelstube','/bastelstube/'],
['Infrastruktur','/infrastruktur/'],
['Organisatorisches','/organisatorisches/'],
['Taktik','/taktik/']
['Bastelstube', '/bastelstube/'],
['Infrastruktur', '/infrastruktur/'],
['Organisatorisches', '/organisatorisches/'],
['Taktik', '/taktik/']
];

export default <Partial<AppOptions<DefaultThemeOptions, ViteBundlerOptions>>>{
export default defineUserConfig({
title: 'Wiki - Gruppe Adler',
description: 'Hier dokumentieren wir alles, was keiner liest, aber nicht verloren gehen soll. Unter anderem findest du Anleitung zu Missionsbau, Taktik und Infrastruktur.',
description:
'Hier dokumentieren wir alles, was keiner liest, aber nicht verloren gehen soll. Unter anderem findest du Anleitung zu Missionsbau, Taktik und Infrastruktur.',
lang: 'de',
dest: './dist',
source: '.',
bundler: '@vuepress/bundler-vite',
bundler: viteBundler(),
head: [
['link', { rel: 'manifest', href: '/manifest.webmanifest' }],
['meta', { name: 'theme-color', content: '#000000' }],
['meta', { name: 'theme-color', content: '#000000' }]
],
alias: {
'@assets': path.resolve(__dirname, '../assets/')
'@assets': path.resolve(__dirname, '../assets/'),
'~@assets': path.resolve(__dirname, '../assets/')
},
theme: path.resolve(__dirname, './theme'),
themeConfig: {

theme: gruppeAdlerTheme({
repo: 'gruppe-adler/wiki.gruppe-adler.de',
docsBranch: 'master',
docsDir: 'docs',
Expand All @@ -42,37 +48,55 @@ export default <Partial<AppOptions<DefaultThemeOptions, ViteBundlerOptions>>>{
openInNewWindow: '(öffnet in neuem Fenster)',

navbar: CATEGORIES.map(([text, link]) => ({ text, link })),
sidebar: CATEGORIES.reduce((acc, [text, link]) => ({ ...acc, [link]: getSidebarItems(text, link) }), {}),
sidebar: CATEGORIES.reduce((acc, [text, link]) => ({ ...acc, [link]: getSidebarItems(text, link) }), {
'/wiki-index': [],
'/404': [],
'/': []
}),
sidebarDepth: 1,

tip: 'TIPP',
warning: 'AUFGEPASST',
danger: 'ACHTUNG'
},
markdown: {
code: {
lineNumbers: false
danger: 'ACHTUNG',
themePlugins: {
prismjs: {
lineNumbers: false
}
}
},
}),
shouldPrefetch: false,
plugins: [
['@vuepress/pwa', {}],
['@vuepress/plugin-pwa-popup', <PwaPopupPluginOptions>{
pwaPlugin({
locales: {
'/': { message: 'Neuer Content ist verfügbar.', buttonText: 'Aktualisieren' }
'/': {
install: 'Installieren',
iOSInstall: "Drücke den Share-Button und dann 'zu Homescreen hinzufügen'",
cancel: 'Abbrechen',
close: 'Schließen',
prevImage: 'Vorheriges Bild',
nextImage: 'Nächstes Bild',
desc: 'Beschreibung',
feature: 'Funktionen',
explain:
'Diese App kann auf Ihrem PC oder Mobilgerät installiert werden. Dadurch sieht diese Web-App aus und verhält sich wie jede andere installierte App. Sie finden sie in Ihren App-Listen und können sie an den Startbildschirm, die Startmenüs oder die Taskleisten anheften. Diese installierte Web-App kann auch sicher mit anderen Apps und Ihrem Betriebssystem interagieren.',
hint: 'Neuer Inhalt gefunden.',
update: 'Neue Inhalte sind verfügbar.'
}
}
}],
['@vuepress/plugin-search', <Partial<SearchPluginOptions>>{
locales: { '/': { placeholder: '' }}
}],
['@vuepress/plugin-google-analytics', <GoogleAnalyticsPluginOptions>{
id: 'G-3NYJQ9NKJL',
}],
[path.resolve(__dirname, './plugins/wiki-index'), {}],
[path.resolve(__dirname, './plugins/redirect-from-de'), {}]
}),
searchPlugin({
locales: { '/': { placeholder: '' } }
}),
googleAnalyticsPlugin({
id: 'G-3NYJQ9NKJL'
}),
wikiIndexPlugin,
redirectFromDePlugin,
resolveImageAliasesPlugin
]
};
});

function getSidebarItems(displayName: string, directory: string): (SidebarItem|string)[] {
function getSidebarItems(displayName: string, directory: string): (SidebarItemOptions | string)[] {
// find all md files
let files = fs.readdirSync(path.resolve(__dirname, '..', directory.substr(1))).filter(file => /\.md$/i.test(file));

Expand All @@ -83,16 +107,16 @@ function getSidebarItems(displayName: string, directory: string): (SidebarItem|s
files.unshift('README.md');
}

const children: Array<SidebarItem|string> = files.map(file => {
const children: Array<SidebarItemOptions | string> = files.map(file => {
if (file === 'README.md') return { text: '❔ Einleitung', link: directory };

return `${directory}${file.slice(0, -3)}`; // remove .md extension
return `${directory}${file.slice(0, -3)}`; // remove .md extension
});

return [
{
text: displayName,
children,
children
}
];
}
}
11 changes: 11 additions & 0 deletions docs/.vuepress/plugins/redirect-from-de/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineClientConfig } from '@vuepress/client';

export default defineClientConfig({
enhance: ({ app, router, siteData }) => {
router.addRoute('/', {
path: '/de/:pathMatch(.*)*',
redirect: to => to.fullPath.substring('/de'.length),
name: 'redirect-from-de'
});
}
});
9 changes: 0 additions & 9 deletions docs/.vuepress/plugins/redirect-from-de/clientAppEnhance.ts

This file was deleted.

12 changes: 7 additions & 5 deletions docs/.vuepress/plugins/redirect-from-de/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { PluginObject } from "vuepress";
import { path } from '@vuepress/utils';
import type { PluginObject } from 'vuepress';
import { path, getDirname } from '@vuepress/utils';

export default <PluginObject>{
const __dirname = getDirname(import.meta.url);

export default {
name: '@gruppe-adler/vuepress-plugin-redirect-from-de',
clientAppEnhanceFiles: path.resolve(__dirname, './clientAppEnhance.ts'),
};
clientConfigFile: path.resolve(__dirname, './client.ts')
} satisfies PluginObject;
35 changes: 35 additions & 0 deletions docs/.vuepress/plugins/resolve-images-aliases/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# `@gruppe-adler/vuepress-plugin-resolve-images-aliases`

This plugin ensures that the `alias` options from the user config is applied to images in markdown.

From the [Vuepress docs](https://v2.vuepress.vuejs.org/guide/assets.html#packages-and-path-aliases):

> Although it is not a common usage, you can reference images from dependent packages:
>
> ```bash
> npm install -D package-name
> ```
>
> Since markdown image syntax regards image links as relative paths by default, you need to use `<img>` tag:
>
> ```md
> <img src="package-name/image.png" alt="Image from dependency">
> ```
>
> The path aliases that set in config file are also supported:
>
> ```ts
> import { getDirname, path } from 'vuepress/utils';
>
> const __dirname = getDirname(import.meta.url);
>
> export default {
> alias: {
> '@alias': path.resolve(__dirname, './path/to/some/dir')
> }
> };
> ```
>
> ```md
> <img src="@alias/image.png" alt="Image from path alias">
> ```
36 changes: 36 additions & 0 deletions docs/.vuepress/plugins/resolve-images-aliases/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { PluginObject } from 'vuepress';
import { path, getDirname } from '@vuepress/utils';
import * as MarkdownIt from 'markdown-it';

const __dirname = getDirname(import.meta.url);

export default {
name: '@gruppe-adler/vuepress-plugin-resolve-images-aliases',
extendsMarkdown: async (md: MarkdownIt, app) => {
const userConfig =
app.pluginApi.plugins.find(plugin => plugin.name === 'user-config') ??
({ name: 'user-config', alias: {} } as PluginObject);

const aliasConfig = Object.entries(
typeof userConfig.alias === 'function' ? await userConfig.alias(app, true) : userConfig.alias
) as [string, string][];

md.use(instance => {
const original = instance.renderer.rules.image;

instance.renderer.rules.image = (tokens, idx, options, env, self) => {
const token = tokens[idx];
const src = token.attrGet('src');

const aliasEntry = aliasConfig.find(([prefix]) => src.startsWith(prefix));

if (aliasEntry) {
const [prefix, absPath] = aliasEntry;
token.attrSet('src', src.replace(prefix, absPath));
}

return original(tokens, idx, options, env, self);
};
});
}
} satisfies PluginObject;
Loading

0 comments on commit 3329592

Please sign in to comment.