Context
Reference of `this` in the hooks of a plugin.
this is the context of the site in a hook, in the functions of a view, and in the head and ui.layoutProps options of your config. Its type is Context of vuesho/config:
createSite(docs.toFumadocsSource()).plugins({
name: "site:example",
configure() {
console.log(`${this.getPages().length} pages in ${this.languages.join(", ")}`);
},
});Use a regular function or a method for a hook, not an arrow function, so that this is the context.
The context has the types of the site: getPages() returns its pages, typed by their source, and localizePath() takes its languages. In a function of another file, type this with SiteContext<typeof app>, from a type-only import of vuesho.config.ts:
import type { SiteContext, SiteLang } from "vuesho/config";
import type app from "../../vuesho.config";
export function blogLink(this: SiteContext<typeof app>, lang: SiteLang<typeof app>) {
return { text: "Blog", url: this.localizePath(lang, "/blog") };
}Site
site: thesiteoption of your config.base: the base path of the site, with a trailing slash, like/docs/.plugins: every plugin, in the order they run: yours, the preset, then the built-in ones.signal: anAbortSignal, aborted when another site replaces this one, like after an edit ofvuesho.config.ts, of a custom page or of the theme in development. Pass it to what a plugin starts, likefs.watch(dir, { signal: this.signal }), so the replaced site stops it.
Content
getPages(lang?): the content pages, of every language or of one.getPage(path): a content page by its URL, without the base path.getLoader(): the content loader of Fumadocs, from theconfigurehook on. Its URLs are encoded, so read pages withgetPages()andgetPage(), and use the loader for its other lookups, likegetPageByHref().getPageTree(lang?): the page tree of a language as the browser receives it, the default language when you omit it.getPageBody(page),getPageToc(page),getPageText(page),getPageStructuredData(page),getPageLastModified(page),getPageCreatedAt(page)andgetPageFile(page): the first result of that content hook among plugins.getPageData(page): the data of a page that the browser receives, after thetransformPagehook of plugins.getPageData(route, path)gives the data of the page atpathof a page route.getContent(path, request?): what the browser receives for a URL, with itskind: a content page, a view, a custom page, or the not found page at/404. It'sundefinedfor a URL without a page.requestreaches thedata,viewandpropsfunctions of a route that renders on demand.getPageRender(path):"static"when the build generates the page atpath,"dynamic"when the server renders it on demand, andundefinedfor a path without a page. It reads the source or the route of the page, then the route rules, see What Renders on Demand. A route made from each page, like a Markdown copy at<page>.md, lists a page instaticPathsonly when it's"static", and a route withrender: "dynamic"at the samepathanswers the others.getContentRender(source?):"dynamic"when a source is dynamic or one of its pages renders on demand,"static"otherwise. Pass the key of a source, or a list of keys, to check those sources only.getCacheControl(page): theCache-Controlheader of a page of a dynamic source with astaleTime, likepublic, s-maxage=60, for a route of your own that renders the page. It'sundefinedfor other pages.revalidateLoader(source?): reads the dynamic sources again now, or the source of one key. The requests that start afterwards have the new pages.invalidateLoader(source?): marks the dynamic sources stale, or the source of one key, so the next request reads them again.
A request reads the content as it was when it started: getPages(), getPage(), getPageTree() and getLoader() agree with each other for the whole request, while a dynamic source changes. Code outside a request, like the configure hook, reads the content as the loader last read it.
Languages
i18n: thei18noption of the content,undefinedon a site without languages.languages: the languages of the site. Withouti18n, it'ssite.langalone, or"en".defaultLanguage: the default language.translations: theui.translationsof your config, with the keys that plugins add. It isundefinedwithoutui.translations.getSite(lang): the site in a language: itsnameanddescription, its language taglang, itslabelin the language switch, itslinkand the direction of its textdir, fromsiteandsite.languages.getLanguage(path): the language of a URL.localizePath(lang, path): a path in a language, with the language prefix unlesshideLocalehides it.getPageAlternates(page): the page in every language it exists in, itself included, as a list of{ lang, url }. It's empty when the page has no translation.getFallbackOrigin(page): for a page that shows the fallback language because its own language has no file for it, the page of the fallback language it shows, which is its canonical URL. It'sundefinedfor a page with its own file.
Routes and Pages
getPageRoutes(): the page routes, the most specific first: the views of plugins, the custom pages and the not found page of each language, one route per language. Each has itspathwith the language prefix,lang,render, thepagesit lists with theirparamsandtranslations, anddata. It throws in therouteshook, see Derived Routes.getLayoutProps({ lang }): the props every layout shares in a language, fromui.layoutPropsof your config and thelayoutPropshook of plugins.getHead(env): the tags of the<head>of a page, from your config, theheadhook of plugins andheadof the theme.
URLs
withBase(path): adds the base path to a path of the site and encodes it, likewithBase()ofvuesho/client. A full URL, a hash or a relative path is returned as it is.absoluteUrl(path): the full URL of a path, with the base path andsite.baseUrl. Withoutsite.baseUrl, it's the path with the base path.getFileUrl(file): the URL of a file on the host ofsite.git, withfilefrom the project root, likecontent/guide.md. It'sundefinedwithoutsite.git, and for a file outside the repository.
Outside of Hooks
getSiteContext() returns the context of the running site, for server code that has no this, like a module that your API handlers call:
import { getSiteContext } from "vuesho/config";
import type app from "../../vuesho.config";
export function pageUrls(): string[] {
return getSiteContext<typeof app>()
.getPages()
.map((page) => page.url);
}During a request, it returns the site that serves the request, so two sites in one process each read their own. Outside of a request, it returns the site that started serving last. It throws before the site has started, so call it in a handler, not when the module loads. It's for the server only: your Vue components run in the browser too.