From 6f2a2af1fff706019244421d70d5165d5fd3c22b Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Sun, 24 Sep 2023 17:40:38 +0530 Subject: [PATCH] chore: fix types --- package.json | 2 +- pnpm-lock.yaml | 9 +-- src/node/contentLoader.ts | 5 +- src/node/index.ts | 18 +++--- src/node/markdown/{index.ts => markdown.ts} | 0 src/node/markdown/plugins/highlight.ts | 2 +- src/node/markdownToVue.ts | 2 +- src/node/plugins/localSearchPlugin.ts | 2 +- .../postcss/{index.ts => isolateStyles.ts} | 0 src/node/siteConfig.ts | 2 +- types/shared.d.ts | 57 ++++++++++++++++++- 11 files changed, 77 insertions(+), 22 deletions(-) rename src/node/markdown/{index.ts => markdown.ts} (100%) rename src/node/postcss/{index.ts => isolateStyles.ts} (100%) diff --git a/package.json b/package.json index f69ebaf6..e2939a0a 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "dependencies": { "@docsearch/css": "^3.5.2", "@docsearch/js": "^3.5.2", + "@types/markdown-it": "^13.0.1", "@vue/devtools-api": "^6.5.0", "@vueuse/core": "^10.4.1", "@vueuse/integrations": "^10.4.1", @@ -135,7 +136,6 @@ "@types/fs-extra": "^11.0.2", "@types/lodash.template": "^4.5.1", "@types/mark.js": "^8.11.8", - "@types/markdown-it": "^13.0.1", "@types/markdown-it-attrs": "^4.1.0", "@types/markdown-it-container": "^2.0.6", "@types/markdown-it-emoji": "^2.0.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 08509159..83831f03 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: '@docsearch/js': specifier: ^3.5.2 version: 3.5.2(@algolia/client-search@4.20.0)(search-insights@2.8.2) + '@types/markdown-it': + specifier: ^13.0.1 + version: 13.0.1 '@vue/devtools-api': specifier: ^6.5.0 version: 6.5.0 @@ -108,9 +111,6 @@ importers: '@types/mark.js': specifier: ^8.11.8 version: 8.11.8 - '@types/markdown-it': - specifier: ^13.0.1 - version: 13.0.1 '@types/markdown-it-attrs': specifier: ^4.1.0 version: 4.1.0 @@ -1258,7 +1258,6 @@ packages: /@types/linkify-it@3.0.3: resolution: {integrity: sha512-pTjcqY9E4nOI55Wgpz7eiI8+LzdYnw3qxXCfHyBDdPbYvbyLgWLJGh8EdPvqawwMK1Uo1794AUkkR38Fr0g+2g==} - dev: true /@types/lodash.template@4.5.1: resolution: {integrity: sha512-0y71S2dGgmwdkSsyW95JBp8HSZchgKCsjr6F0lsT3eSMtaT3Nn9rcMHU1U4UKu6XjQT3YC6/PNwgFI7k9f+ltw==} @@ -1299,11 +1298,9 @@ packages: dependencies: '@types/linkify-it': 3.0.3 '@types/mdurl': 1.0.2 - dev: true /@types/mdurl@1.0.2: resolution: {integrity: sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA==} - dev: true /@types/micromatch@4.0.2: resolution: {integrity: sha512-oqXqVb0ci19GtH0vOA/U2TmHTcRY9kuZl4mqUxe0QmJAlIW13kzhuK5pi1i9+ngav8FjpSb9FVS/GE00GLX1VA==} diff --git a/src/node/contentLoader.ts b/src/node/contentLoader.ts index 6eaf8be6..c213f794 100644 --- a/src/node/contentLoader.ts +++ b/src/node/contentLoader.ts @@ -4,7 +4,10 @@ import glob from 'fast-glob' import type { SiteConfig } from './config' import matter from 'gray-matter' import { normalizePath } from 'vite' -import { createMarkdownRenderer, type MarkdownRenderer } from './markdown' +import { + createMarkdownRenderer, + type MarkdownRenderer +} from './markdown/markdown' export interface ContentOptions { /** diff --git a/src/node/index.ts b/src/node/index.ts index 79432a9b..90c0956a 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -1,18 +1,18 @@ -export * from './config' -export * from './server' -export * from './markdown' +export { loadEnv, type Plugin } from 'vite' export * from './build/build' -export * from './serve/serve' -export * from './init/init' +export * from './config' export * from './contentLoader' -export * from './postcss' +export * from './init/init' +export * from './markdown/markdown' export { defineLoader, type LoaderModule } from './plugins/staticDataPlugin' -export { loadEnv, type Plugin } from 'vite' +export * from './postcss/isolateStyles' +export * from './serve/serve' +export * from './server' // shared types export type { - SiteData, + DefaultTheme, HeadConfig, Header, - DefaultTheme + SiteData } from '../../types/shared' diff --git a/src/node/markdown/index.ts b/src/node/markdown/markdown.ts similarity index 100% rename from src/node/markdown/index.ts rename to src/node/markdown/markdown.ts diff --git a/src/node/markdown/plugins/highlight.ts b/src/node/markdown/plugins/highlight.ts index 29dd5198..52463286 100644 --- a/src/node/markdown/plugins/highlight.ts +++ b/src/node/markdown/plugins/highlight.ts @@ -17,7 +17,7 @@ import { type Processor } from 'shiki-processor' import type { Logger } from 'vite' -import type { ThemeOptions } from '..' +import type { ThemeOptions } from '../markdown' const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10) diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index 891ff56d..0648f456 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -8,7 +8,7 @@ import { createMarkdownRenderer, type MarkdownOptions, type MarkdownRenderer -} from './markdown' +} from './markdown/markdown' import { EXTERNAL_URL_RE, slash, diff --git a/src/node/plugins/localSearchPlugin.ts b/src/node/plugins/localSearchPlugin.ts index 4b0037cc..dc7ca8da 100644 --- a/src/node/plugins/localSearchPlugin.ts +++ b/src/node/plugins/localSearchPlugin.ts @@ -4,7 +4,7 @@ import MiniSearch from 'minisearch' import path from 'path' import type { Plugin, ViteDevServer } from 'vite' import type { SiteConfig } from '../config' -import { createMarkdownRenderer } from '../markdown' +import { createMarkdownRenderer } from '../markdown/markdown' import { resolveSiteDataByRoute, slash, diff --git a/src/node/postcss/index.ts b/src/node/postcss/isolateStyles.ts similarity index 100% rename from src/node/postcss/index.ts rename to src/node/postcss/isolateStyles.ts diff --git a/src/node/siteConfig.ts b/src/node/siteConfig.ts index d5ec6b83..10cd3967 100644 --- a/src/node/siteConfig.ts +++ b/src/node/siteConfig.ts @@ -3,7 +3,7 @@ import type { UseDarkOptions } from '@vueuse/core' import type { SitemapStreamOptions } from 'sitemap' import type { Logger, UserConfig as ViteConfig } from 'vite' import type { SitemapItem } from './build/generateSitemap' -import type { MarkdownOptions } from './markdown' +import type { MarkdownOptions } from './markdown/markdown' import type { Awaitable, HeadConfig, diff --git a/types/shared.d.ts b/types/shared.d.ts index 5e95cdba..99a9b57a 100644 --- a/types/shared.d.ts +++ b/types/shared.d.ts @@ -1,5 +1,4 @@ // types shared between server and client -import type { MarkdownSfcBlocks } from '@mdit-vue/plugin-sfc' import type { UseDarkOptions } from '@vueuse/core' import type { SSRContext } from 'vue/server-renderer' export type { DefaultTheme } from './default-theme.js' @@ -19,6 +18,62 @@ export interface PageData { lastUpdated?: number } +/** + * SFC block extracted from markdown + */ +export interface SfcBlock { + /** + * The type of the block + */ + type: string + /** + * The content, including open-tag and close-tag + */ + content: string + /** + * The content that stripped open-tag and close-tag off + */ + contentStripped: string + /** + * The open-tag + */ + tagOpen: string + /** + * The close-tag + */ + tagClose: string +} + +export interface MarkdownSfcBlocks { + /** + * The `