Initalize

This commit is contained in:
Your Name
2026-05-03 12:12:57 -04:00
commit 38652eb9b5
10603 changed files with 1762136 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import Debug from 'debug';
import {EOL} from 'node:os';
const pivot = 'export default function(app) {';
export default function(layouts = [], {debug = Debug('@lando/vite-plugin')}) { // eslint-disable-line
return {
name: 'inject-layouts',
enforce: 'pre',
transform: (code, id) => {
const layoutfile = 'enhance-app-with-layouts.js';
if (id.includes(layoutfile) && layouts.length > 0) {
// get lines and pindex
const lines = code.split(EOL);
// get pivot line
let pindex = lines.findIndex(line => line.startsWith(pivot));
// loop through and add imports
for (const layout of layouts.reverse()) lines.splice(pindex, 0, layout.import);
// get pivot again
pindex = lines.findIndex(line => line.startsWith(pivot)) + 1;
// loop through again and add components
for (const layout of layouts.reverse()) lines.splice(pindex, 0, layout.add);
// debug
debug('autogenerated layout import file %o with content %O', layoutfile, lines);
return lines.join(EOL);
}
},
};
};

View File

@@ -0,0 +1,15 @@
import Debug from 'debug';
export default function({debug = Debug('@lando/vite-plugin')}) { // eslint-disable-line
return {
name: 'vp-menugroup-columns',
enforce: 'pre',
transform: (code, id) => {
const menufile = 'VPMenu.vue';
if (id.endsWith(menufile)) {
debug('patched %o to add columns support to dropdown menu groups', menufile);
return code.replace(':items="item.items"', ':items="item.items" :columns="item.columns"');
}
},
};
};

View File

@@ -0,0 +1,39 @@
import Debug from 'debug';
import {EOL} from 'node:os';
export default function({debug = Debug('@lando/vite-plugin')}) { // eslint-disable-line
return {
name: 'vp-use-sidebar-control',
enforce: 'pre',
transform: (code, id) => {
const supportfile = 'dist/client/theme-default/composables/sidebar.js';
if (id.includes(supportfile)) {
// prepend our mvb normalizer
code = `import { getItemNormalizedLink } from '@lando/vitepress-theme-default-plus';${EOL}${code}`;
code = `import { normalizeItems } from '@lando/vitepress-theme-default-plus';${EOL}${code}`;
// make sure we get "site" as well
code = code.replace(
'const { page, hash } = useData()',
'const { site, page, hash } = useData()',
);
// and then use getItemNormalizedLink
code = code.replace(
'isActive(page.value.relativePath, item.value.link)',
'isActive(page.value.relativePath, getItemNormalizedLink(item.value, site.value))',
);
// and also use normalizeItems
code = code.replace(
'containsActiveLink(page.value.relativePath, item.value.items)',
'containsActiveLink(page.value.relativePath, normalizeItems(item.value.items, site.value))',
);
// log
debug('patched %o to use getItemNormalizedLink', supportfile);
return code;
}
},
};
};

View File

@@ -0,0 +1,79 @@
import axios from 'axios';
import matter from 'gray-matter';
import merge from 'lodash-es/merge.js';
import Debug from 'debug';
import {EOL} from 'node:os';
// return updated content
const getContent = (remote, og, config) => {
switch (config.content) {
case 'append': return `${og.content}${EOL}${remote.content}`;
case 'prepend': return `${remote.content}${EOL}${og.content}`;
case 'replace': return remote.content;
default: return remote.content;
}
};
// return updated frontmatter
const getFrontmatter = (remote, og, config) => {
switch (config.frontmatter) {
case 'merge': return merge({}, og.data, remote.data);
case 'rebase': return merge({}, remote.data, og.data);
case 'replace': return remote.data;
case 'omit':
case 'skip':
case false:
return og.data;
default: return remote.data;
}
};
// return a standard url-loader config object with defaults
const normalize = config => {
// if config is a string then reset to an object
if (typeof config === 'string') config = {source: config};
// return with mixed in defaults
return merge({}, {content: 'replace', frontmatter: 'replace'}, config);
};
export default function({debug = Debug('@lando/url-loader')}) { // eslint-disable-line
return {
name: 'url-loader',
enforce: 'pre',
async transform(code, id) {
if (id.endsWith('.md')) {
// get original content stuff
const og = matter(code);
// if we have a url-loader then proceed
if (og?.data?.['url-loader']) {
// normalize loader
const config = normalize(og.data['url-loader']);
debug('fetching content for %o from %o with %o', id, config.source, {config});
// attempt to get raw remote source code
try {
new URL(config.source);
config.response = await axios.get(config.source);
} catch (error) {
error.message = `Fetching ${config.source} for ${id} failed with: ${error.message}`;
throw error;
}
// parse remote content
const remote = matter(config?.response?.data ?? '');
// build new content/frontmatter
const content = getContent(remote, og, config);
const frontmatter = getFrontmatter(remote, og, config);
// stringify and retturn
return matter.stringify(content, frontmatter);
}
}
return null;
},
};
};