Skip to content

Commit

Permalink
Change to DocumenterVitepress
Browse files Browse the repository at this point in the history
  • Loading branch information
natgeo-wong committed Oct 5, 2024
1 parent f7d56d2 commit 0923871
Show file tree
Hide file tree
Showing 9 changed files with 608 additions and 9 deletions.
3 changes: 1 addition & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Documenter
using DocumenterVitepress
using RegionGrids
# using CairoMakie
# using Literate
# import CairoMakie

# CairoMakie.activate!(type = "svg")

Expand Down
48 changes: 48 additions & 0 deletions docs/src/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { defineConfig } from 'vitepress'
import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'
import mathjax3 from "markdown-it-mathjax3";
import footnote from "markdown-it-footnote";

// https://vitepress.dev/reference/site-config
export default defineConfig({
base: 'REPLACE_ME_DOCUMENTER_VITEPRESS',// TODO: replace this in makedocs!
title: 'REPLACE_ME_DOCUMENTER_VITEPRESS',
description: "A VitePress Site",
lastUpdated: true,
cleanUrls: true,
outDir: 'REPLACE_ME_DOCUMENTER_VITEPRESS', // This is required for MarkdownVitepress to work correctly...
head: [['link', { rel: 'icon', href: 'REPLACE_ME_DOCUMENTER_VITEPRESS_FAVICON' }]],
ignoreDeadLinks: true,

markdown: {
math: true,
config(md) {
md.use(tabsMarkdownPlugin),
md.use(mathjax3),
md.use(footnote)
},
theme: {
light: "github-light",
dark: "github-dark"}
},
themeConfig: {
outline: 'deep',
logo: 'REPLACE_ME_DOCUMENTER_VITEPRESS',
search: {
provider: 'local',
options: {
detailedView: true
}
},
nav: 'REPLACE_ME_DOCUMENTER_VITEPRESS',
sidebar: 'REPLACE_ME_DOCUMENTER_VITEPRESS',
editLink: 'REPLACE_ME_DOCUMENTER_VITEPRESS',
socialLinks: [
{ icon: 'github', link: 'REPLACE_ME_DOCUMENTER_VITEPRESS' }
],
footer: {
message: 'Made with <a href="https://documenter.juliadocs.org/stable/" target="_blank"><strong>Documenter.jl</strong></a> & <a href="https://vitepress.dev" target="_blank"><strong>VitePress</strong></a> <br>',
copyright: `© Copyright ${new Date().getUTCFullYear()}.`
}
}
})
55 changes: 55 additions & 0 deletions docs/src/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// .vitepress/theme/index.ts
import { watch } from 'vue'
import type { Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme'

import { enhanceAppWithTabs } from 'vitepress-plugin-tabs/client'
import './style.css'

export default {
extends: DefaultTheme,
async enhanceApp({ app, router, siteData }) {
enhanceAppWithTabs(app);
// Only run this on the client. Not during build.
// this function replaces the version in the URL with the stable prefix whenever a
// new route is navigated to. VitePress does not support relative links all over the site,
// so urls will go to v0.XY even if we start at stable. This solution is not ideal as
// there is a noticeable delay between navigating to a new page and editing the url, but it's
// currently better than nothing, as users are bound to copy versioned links to the docs otherwise
// which will lead users to outdated docs in the future.
if (typeof window !== "undefined") {
function rewriteURL() {
// DOCUMENTER_NEWEST is defined in versions.js, DOCUMENTER_CURRENT_VERSION and DOCUMENTER_STABLE
// in siteinfo.js.
if (
window.DOCUMENTER_NEWEST === undefined ||
window.DOCUMENTER_CURRENT_VERSION === undefined ||
window.DOCUMENTER_STABLE === undefined
) {
return;
}

// Current version is newest version, so we can rewrite the url
if (window.DOCUMENTER_NEWEST === window.DOCUMENTER_CURRENT_VERSION) {
const rewritten_url = window.location.href.replace(
window.DOCUMENTER_CURRENT_VERSION,
window.DOCUMENTER_STABLE
);
window.history.replaceState(
{ additionalInformation: "URL rewritten to stable" },
"DimensionalData",
rewritten_url
);
return;
}
}

// rewrite on router changes through vitepress
watch(() => router.route.data.relativePath, rewriteURL, {
immediate: true,
});
// also rewrite at initial load
document.addEventListener("DOMContentLoaded", rewriteURL);
}
},
} satisfies Theme;
Loading

0 comments on commit 0923871

Please sign in to comment.