Skip to content

Commit

Permalink
first pass on theme composables, data, etc for multi version build stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Sep 30, 2024
1 parent 6070608 commit 9688a09
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 53 deletions.
5 changes: 2 additions & 3 deletions bin/vitepress-mvb.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node
import path from 'node:path';
import fs from 'fs-extra';
import semver from 'semver';

import {tmpdir} from 'node:os';
import {nanoid} from 'nanoid';
Expand Down Expand Up @@ -99,7 +98,7 @@ exec('npm clean-install');
// push aliases
// unshift root

process.exit(1)
process.exit(1);

// loop through and build
// git reset HEAD --hard
Expand All @@ -126,7 +125,7 @@ const owdOutDir = path.resolve(owd, srcDir, outDir);
if (clean) fs.removeSync(owdOutDir, {force: true, maxRetries: 10, recursive: true});

// then move tmp to owd
console.log(tmpOutDir, owdOutDir)
console.log(tmpOutDir, owdOutDir);
fs.moveSync(tmpOutDir, owdOutDir);

// done?
18 changes: 17 additions & 1 deletion client/use-tags.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import {data as tags} from './tags.data.js';

import {useData} from 'vitepress';

export default function useTags() {
return tags;
// get version path data
const {theme} = useData();
const vp = theme?.value?.multiVersionBuild?.path ?? '/v/';

// generate links we can pass into VPLVersionLink
const links = tags.versions
.map(version => ({
text: version,
href: `${vp}${version}/`,
prerelease: /^v?\d+\.\d+\.\d+-\S+$/.test(version),
stable: tags?.aliases?.stable === version,
edge: tags?.aliases?.edge === version,
}));

return {...tags, links};
}
1 change: 0 additions & 1 deletion components/VPLLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,3 @@ watch(() => page.value.relativePath, () => {
padding: 16px 0 ;
}
</style>
62 changes: 55 additions & 7 deletions components/VPLVersionLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,38 @@
<a
class="VPLink"
:class="{
'prerelease': props.prerelease,
link: props.href,
'vp-external-link-icon': props.target === '_blank',
'no-icon': props.noIcon
}"
:href="props.href"
:href="normalizeLink(props.href)"
:target="props.target"
:rel="props.rel"
>
{{ props.text }}
<Badge
v-if="props.stable"
type="success"
text="STABLE"
vertical="middle"
/>
<Badge
v-if="props.edge"
type="warning"
text="EDGE"
vertical="middle"
/>
<Badge
v-if="props.dev"
type="tip"
text="DEV"
vertical="middle"
/>
</a>
</template>

<script setup>
import {computed} from 'vue';
import {normalizeLink} from 'vitepress/dist/client/theme-default/support/utils.js';
const props = defineProps({
Expand All @@ -27,20 +45,50 @@ const props = defineProps({
type: String,
default: undefined,
},
dev: {
type: Boolean,
default: false,
},
edge: {
type: Boolean,
default: false,
},
noIcon: {
type: Boolean,
default: false,
},
target: {
type: String,
default: '_blank',
prerelease: {
type: Boolean,
default: false,
},
rel: {
type: String,
default: undefined,
},
stable: {
type: Boolean,
default: false,
},
target: {
type: String,
default: '_blank',
},
});
</script>


<style lang="scss">
.version-link {
a {
color: var(--vp-c-green-3);
&:hover {
color: var(--vp-c-green-3);
}
}
a.prerelease {
color: var(--vp-c-yellow-3);
&:hover {
color: var(--vp-c-yellow-3);
}
}
}
</style>
2 changes: 1 addition & 1 deletion config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default function({base}) {
},
},
layouts: {},
multiVersion: false,
multiVersionBuild: false,
nav: [],
sidebar: {},
sidebarEnder: false,
Expand Down
15 changes: 13 additions & 2 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default defineConfig({
robots: {
host: 'https://vitepress-theme-default-plus.lando.dev/',
sitemap: 'https://vitepress-theme-default-plus.lando.dev/sitemap.xml',
disallowAll: false,
allowAll: false,
policies: [{
userAgent: '*',
disallow: ['/v/'],
Expand Down Expand Up @@ -125,7 +127,7 @@ export default defineConfig({
multiVersionBuild: {
rootBuild: 'stable',
match: 'v[0-9].*',
path: 'v',
path: '/v/',
satisfies: '>1.0.0-beta.40',
},
tags: {
Expand Down Expand Up @@ -243,8 +245,17 @@ export default defineConfig({
text: `v${version}`,
collapsed: true,
items: [
{
text: 'Other Doc Versions',
items: [
{text: 'stable', target: '_blank', link: '/v/stable/'},
{text: 'edge', target: '_blank', link: '/v/edge/'},
{text: 'dev', target: '_blank', link: '/v/dev/'},
{text: '<strong>see all versions</strong>', link: '/v/'},
],
},
{text: 'Release Notes', link: `https://github.com/lando/vitepress-theme-default-plus/releases/tag/v${version}`},
{text: 'Older Versions', link: 'https://github.com/lando/vitepress-theme-default-plus/releases'},
{text: 'Other Releases', link: 'https://github.com/lando/vitepress-theme-default-plus/releases'},
],
},
},
Expand Down
71 changes: 37 additions & 34 deletions docs/v/index.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
---
description: Learn how to install and get started with VitePress Default Theme Plus!
description: All Other documentation versions
title: Docuversions
contributors: false
lastUpdated: false
editLink: false
next: false
---

# Usage

Before starting make sure you are familiar with [the basics](https://vitepress.dev/guide/getting-started#file-structure) of VitePress theme installation.

To start using the theme you will want to create `.vitepress/theme/index.mjs` and `.vitepress/config.mjs` as below:

## .vitepress/theme/index.mjs

```js
import {VPLTheme} from '@lando/vitepress-theme-default-plus';
export default VPLTheme;
```

If you want to extend our theme you should consult the [official docs](https://vitepress.dev/guide/extending-default-theme) on how to best do that.

## .vitepress/config.mjs

Import our `defineConfig` wrapper and pass in hte [configuration](./../config/config) you want.

```js
import {defineConfig} from '@lando/vitepress-theme-default-plus/config';

export default defineConfig({
title: 'VitePress Theme +',
description: 'The VitePress default theme with some MOARPOWAH!',
base: '/',
lang: 'en-US',
themeConfig: {
...
},
...
});
```
# Docuversions

<br />
<br />

<div
v-for="link in links"
:key="link.text"
class="version-link"
>
<VPLVersionLink
:text="link.text"
:href="link.href"
:prerelease="link.prerelease"
:stable="link.stable"
:edge="link.edge"
/>
</div>

<br />

<div>
<VPLVersionLink :dev="true" :text="aliases.dev" href="/v/dev/" />
</div>

<script setup>
import {useTags} from '@lando/vitepress-theme-default-plus';
import {VPLCollectionPage, VPLCollectionPageSection, VPLCollectionPageTitle, VPLVersionLink} from '@lando/vitepress-theme-default-plus';

const {aliases, links} = useTags();
</script>
2 changes: 1 addition & 1 deletion node/add-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default async function(pageData, {
const description = frontmatter.description ?? frontmatter.summary ?? site.description;
const i = frontmatter.image ?? image ?? site?.logo?.src;
const xandle = x ?? twitter;
const published = new Date(lastUpdated);
const published = new Date(Number.isNaN(lastUpdated) || !lastUpdated ? Date.now() : lastUpdated);

// generics
frontmatter.head.push(
Expand Down
6 changes: 5 additions & 1 deletion node/generate-robots.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export default async function({userConfig, outDir}, {debug = Debug('@lando/gener
// get robots config or defaults
const robots = merge({}, defaults, userConfig.robots || userConfig?.themeConfig?.robots);

// munge policies together
robots.policy = [...robots.policy, ...robots.policies].filter(policy => policy);

// if no polices and disallowAll=false then assume allowAll
if (Array.isArray(robots.policy) && robots.policy.length === 0 && !robots.disallowAll) robots.allowAll = true;

Expand All @@ -45,13 +48,14 @@ export default async function({userConfig, outDir}, {debug = Debug('@lando/gener
if (host) options.host = host;
// add sitemap
if (sitemap) options.sitemap = sitemap;
debug('resolved robots.txt config from %o to %o', robots, options);

// write file
try {
const dest = resolve(outDir, robots.file);
const content = await robotstxt(options);
writeFileSync(dest, content);
debug('generated %o with content %O', dest, content);
debug('generated %o with content \n%O', dest, content);
} catch (error) {
throw error;
}
Expand Down
18 changes: 18 additions & 0 deletions styles/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,24 @@ nav#VPSidebarNav {
svg {
color: var(--vp-c-green-3) !important;
}
.VPSidebarItem.level-1 {
.item {
h3.text {
font-weight: 700;
color: var(--vp-c-text-1);
}
}
.items {
.text {
font-size: .90em;
}
border-left: 0;
padding-left: 0;
border-bottom: 1px solid var(--vp-c-divider);
padding-bottom: 24px;
margin-bottom: 10px;
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions vitepress-theme-default-plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import VPLYouTube from './components/VPLYouTube.vue';
export {default as isActive} from './client/is-active.js';
export {default as encodeTag} from './client/encode-tag.js';
export {default as useCollection} from './client/use-collection.js';
// export {default as useTags} from './client/use-tags.js';
export {default as useTags} from './client/use-tags.js';
export {default as useTeam} from './client/use-team.js';

// components
export {default as VPLAlert} from './components/VPLAlert.vue';
export {default as VPLLink} from './components/VPLLink.vue';
export {default as VPLMenuGroup} from './components/VPLMenuGroup.vue';
export {default as VPLMenuLink} from './components/VPLMenuLink.vue';
// export {default as VPLVersionLink} from './components/VPLVersionLink.vue';
export {default as VPLVersionLink} from './components/VPLVersionLink.vue';
export {default as VPLNavBarMenuGroup} from './components/VPLNavBarMenuGroup.vue';

// team page
Expand Down

0 comments on commit 9688a09

Please sign in to comment.