diff --git a/CHANGELOG.md b/CHANGELOG.md index 91d75929..71afd44b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,10 @@ ## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }}) * Added `getItemNormalizedLink` helper client util -* Added `hasActiveLink` helper client util * Added `normalize2base` helper client util * Added `normalizeMVB` helper client util * Added `normalizeRoot` helper client util * Added `version` alias information to config -* Added `VPLSidebarEnder` component to better handle `mvb` things * Fixed bug preventing user specified `buildEnd` and `transformPageData` from running after theme's * Fixed bug preventing `mvb` from correctly setting the `mvbase` * Improved `mvb` and `root` link normalization diff --git a/client/get-item-nl.js b/client/get-item-nl.js index e912988b..11da8695 100644 --- a/client/get-item-nl.js +++ b/client/get-item-nl.js @@ -1,19 +1,14 @@ import {useData} from 'vitepress'; import {default as normalize} from './normalize-2base.js'; -import {default as normalizeMvb} from './normalize-mvblink.js'; -import {default as normalizeRoot} from './normalize-rootlink.js'; export default function getItemNormalizedLink(item) { // if we dont have what we need just return that garbage if (!item.link) return item.link; - const {site} = useData(); - const base = site?.value?.base ?? '/'; - - // handle special rels - if (item.rel === 'mvb') return normalizeMvb(item.link); - else if (item.rel === 'root') return normalizeRoot(item.link); + // if this is not a special mvb then just return + if (item.rel !== 'mvb') return item.link; - // and this is everythign else - return normalize(item.link, base); + // otherwise normalize on version base + const {site} = useData(); + return normalize(item.link, site?.value?.themeConfig?.multiVersionBuild?.base ?? '/'); }; diff --git a/client/has-active-link.js b/client/has-active-link.js deleted file mode 100644 index e3756cd9..00000000 --- a/client/has-active-link.js +++ /dev/null @@ -1,15 +0,0 @@ - -import {default as getItemNormalizedLink} from './get-item-nl.js'; -import {default as isActive} from './is-active.js'; - -export default function hasActiveLink(path, items) { - if (Array.isArray(items)) { - return items.some(item => hasActiveLink(path, item)); - } - - return isActive(path, getItemNormalizedLink(items)) - ? true - : items.items - ? hasActiveLink(path, items.items) - : false; -}; diff --git a/components/VPLLayout.vue b/components/VPLLayout.vue index 7e0e5082..0bc1abaf 100644 --- a/components/VPLLayout.vue +++ b/components/VPLLayout.vue @@ -15,7 +15,10 @@ v-if="sidebarEnder !== false" class="sidebar-end" > - + @@ -55,12 +58,12 @@ import {useData} from 'vitepress'; import {computed, ref, watch} from 'vue'; import DefaultTheme from 'vitepress/theme'; +import VPSideBarItem from 'vitepress/dist/client/theme-default/components/VPSidebarItem.vue'; import Alert from './VPLAlert.vue'; import CollectionHeader from './VPLCollectionHeader.vue'; import MailChimp from './VPLMailChimp.vue'; import PostHeader from './VPLPostHeader.vue'; -import SidebarEnder from './VPLSidebarEnder.vue'; import Tags from './VPLCollectionItemTags.vue'; const {Layout} = DefaultTheme; diff --git a/components/VPLSidebarEnder.vue b/components/VPLSidebarEnder.vue deleted file mode 100644 index 90bf5dc3..00000000 --- a/components/VPLSidebarEnder.vue +++ /dev/null @@ -1,304 +0,0 @@ - - - - - diff --git a/config.js b/config.js index b7340547..60a4e74b 100644 --- a/config.js +++ b/config.js @@ -32,10 +32,13 @@ import {default as parseCollections} from './node/parse-collections.js'; import {default as generateFeeds} from './node/generate-feeds.js'; import {default as generateRobotsTxt} from './node/generate-robots.js'; import {default as linkOverridePlugin} from './markdown/link-override-plugin.js'; -import {default as patchVPMenuColumnsPlugin} from './vite/patch-vp-menu-columns-plugin.js'; import {tabsMarkdownPlugin} from 'vitepress-plugin-tabs'; import {default as tabsMarkdownOverridePlugin} from './markdown/tabs-override-plugin.js'; +// vitepress patches +import {default as patchVPHasActiveLink} from './vite/patch-vp-has-active-link.js'; +import {default as patchVPMenuColumnsPlugin} from './vite/patch-vp-menu-columns-plugin.js'; + // configsets import {default as baseConfig} from './config/defaults.js'; import {default as lando3BaseConfig} from './config/landov3.js'; @@ -131,6 +134,7 @@ export async function defineConfig(userConfig = {}, defaults = {}) { vite.plugins.push(...[ addLayoutsPlugin(layouts, {debug: debug.extend('vite-plugin')}), patchVPMenuColumnsPlugin({debug: debug.extend('vite-plugin')}), + patchVPHasActiveLink({debug: debug.extend('vite-plugin')}), ]); // deps diff --git a/vite/patch-vp-has-active-link.js b/vite/patch-vp-has-active-link.js new file mode 100644 index 00000000..51d6a292 --- /dev/null +++ b/vite/patch-vp-has-active-link.js @@ -0,0 +1,21 @@ +import Debug from 'debug'; +import {EOL} from 'node:os'; + +export default function({debug = Debug('@lando/vite-plugin')}) { // eslint-disable-line + return { + name: 'vp-has-active-links', + enforce: 'pre', + transform: (code, id) => { + const supportfile = 'dist/client/theme-default/support/sidebar.js'; + if (id.includes(supportfile)) { + // prepend our mvb normalizer + code = `import { default as getItemNormalizedLink } from '../../../../../../client/get-item-nl.js';${EOL}${code}`; + // and then use it + code = code.replace('return isActive(path, items.link)', 'return isActive(path, getItemNormalizedLink(items))'); + // log + debug('patched %o to use getItemNormalizedLink', supportfile); + return code; + } + }, + }; +}; diff --git a/vite/patch-vp-menu-columns-plugin.js b/vite/patch-vp-menu-columns-plugin.js index 3e08b1fb..e577ab9f 100644 --- a/vite/patch-vp-menu-columns-plugin.js +++ b/vite/patch-vp-menu-columns-plugin.js @@ -2,7 +2,7 @@ import Debug from 'debug'; export default function({debug = Debug('@lando/vite-plugin')}) { // eslint-disable-line return { - name: 'vpmenugroup-columns', + name: 'vp-menugroup-columns', enforce: 'pre', transform: (code, id) => { const menufile = 'VPMenu.vue'; diff --git a/vitepress-theme-default-plus.js b/vitepress-theme-default-plus.js index 8d0caf98..a11c32dd 100644 --- a/vitepress-theme-default-plus.js +++ b/vitepress-theme-default-plus.js @@ -23,7 +23,6 @@ export {default as isFauxInternal} from './utils/is-faux-internal.js'; export {default as encodeTag} from './client/encode-tag.js'; export {default as getBaseUrl} from './utils/get-base-url.js'; export {default as getItemNormalizedLink} from './client/get-item-nl.js'; -export {default as hasActiveLink} from './client/has-active-link.js'; export {default as normalize2base} from './client/normalize-2base.js'; export {default as normalizeMVB} from './client/normalize-mvblink.js'; export {default as normalizeRoot} from './client/normalize-rootlink.js'; @@ -37,7 +36,6 @@ 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 VPLNavBarMenuGroup} from './components/VPLNavBarMenuGroup.vue'; -export {default as VPLSidebarEnder} from './components/VPLSidebarEnder.vue'; export {default as VPLVersionLink} from './components/VPLVersionLink.vue'; // team page