Skip to content

Commit

Permalink
feat(types): ctx.getSiteData
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Dec 25, 2021
1 parent 4269714 commit 332dac7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/@vuepress/types/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import { PostCssLoaderOptions } from "./style";
import { MarkdownConfig } from "./markdown";
import { LocaleConfig } from "./locale";
import { Locales } from "./locale";
import { ThemeConfig } from "./theme";
import { UserPlugins } from "./plugin";
import { Context } from "./context";
import { ChainWebpack } from "./shared";


/**
* HTML tag name
*/
export type HTMLTagName = keyof HTMLElementTagNameMap;

/**
* Expose `HeadTags`
*/
export type HeadTags = Array<
[
HTMLTagName,
Partial<HTMLElementTagNameMap[HTMLTagName]>,
string? /* innerHTML */
]
>;

/**
* Expose `VuePress` config.
*/
Expand Down Expand Up @@ -39,13 +51,7 @@ export interface Config<T extends ThemeConfig> {
*
* @see https://vuepress.vuejs.org/config/#head
*/
head?: Array<
[
HTMLTagName,
Partial<HTMLElementTagNameMap[HTMLTagName]>,
string? /* innerHTML */
]
>;
head?: HeadTags;
/**
* Specify the host to use for the dev server.
*
Expand Down Expand Up @@ -77,7 +83,7 @@ export interface Config<T extends ThemeConfig> {
*
* @see https://vuepress.vuejs.org/config/#locales
*/
locales?: { [path: string]: LocaleConfig };
locales?: Locales;
/**
* A function to control what files should have <link rel="prefetch"> resource hints generated.
*
Expand Down
5 changes: 5 additions & 0 deletions packages/@vuepress/types/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ThemeConfig } from "./theme";
import { Config } from "./config";
import { Lang } from "./lang";
import { SiteData } from "./site-data";

/**
* Page instance.
Expand Down Expand Up @@ -173,4 +174,8 @@ export interface Context<
* Theme API.
*/
themeAPI: ThemeAPI;
/**
* Get site data.
*/
getSiteData(): SiteData;
}
2 changes: 2 additions & 0 deletions packages/@vuepress/types/src/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ export interface LocaleConfig {
*/
description: string;
}

export type Locales = { [path: string]: LocaleConfig };
14 changes: 14 additions & 0 deletions packages/@vuepress/types/src/site-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Page } from "./context";
import { ThemeConfig } from "./theme";
import { Locales } from "./locale";
import { HeadTags } from "./config";

export interface SiteData<T extends ThemeConfig = ThemeConfig> {
title: string;
description: string;
base: string;
pages: Page[];
headTags: HeadTags;
themeConfig: T;
locales: Locales;
}

0 comments on commit 332dac7

Please sign in to comment.