Skip to content

Commit

Permalink
chore: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Aug 15, 2024
1 parent ff32bf3 commit d85018d
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 65 deletions.
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ export default vuepress(
},
},
{
files: ['**/*.spec.ts'],
files: ['**/tests/**'],
rules: {
'no-console': 'off',
'prefer-template': 'off',
},
},
)
4 changes: 2 additions & 2 deletions packages/core/src/app/createBaseApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const createBaseApp = (config: AppConfig, isBuild = false): App => {

// methods
use: (plugin: Plugin) => appUse(app, plugin),
init: () => appInit(app),
prepare: () => appPrepare(app),
init: async () => appInit(app),
prepare: async () => appPrepare(app),
} as App

// setup theme and plugins
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/app/resolveAppDir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const require = createRequire(import.meta.url)
/**
* Create directory util function
*/
export const createAppDirFunction = (baseDir: string): AppDirFunction => {
return (...args: string[]): string => path.resolve(baseDir, ...args)
}
export const createAppDirFunction =
(baseDir: string): AppDirFunction =>
(...args) =>
path.resolve(baseDir, ...args)

/**
* Resolve directory utils for vuepress app
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/app/resolveAppMarkdown.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createMarkdown } from '@vuepress/markdown'
import type { Markdown } from '@vuepress/markdown'
import { createMarkdown } from '@vuepress/markdown'
import type { App } from '../types/index.js'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/app/resolveAppPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const resolveAppPages = async (app: App): Promise<Page[]> => {

// create pages from files
const pages = await Promise.all(
pageFilePaths.map((filePath) => createPage(app, { filePath })),
pageFilePaths.map(async (filePath) => createPage(app, { filePath })),
)

// find the 404 page
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/page/resolvePageHtmlInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export const resolvePageHtmlInfo = ({
// /foo/ -> foo/index.html
const htmlFilePathRelative = removeLeadingSlash(
path.endsWith('/')
? path + 'index.html'
? `${path}index.html`
: path.endsWith('.html')
? path
: path + '.html',
: `${path}.html`,
)
const htmlFilePath = app.dir.dest(htmlFilePathRelative)

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/page/resolvePagePermalink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export const resolvePagePermalink = ({
const link = path.join(
pathLocale,
permalinkPattern
.replace(/:year/, year!)
.replace(/:month/, month!)
.replace(/:day/, day!)
.replace(/:year/, year)
.replace(/:month/, month)
.replace(/:day/, day)
.replace(/:slug/, slug)
.replace(/:raw/, pathInferred?.replace(/^\//, '') ?? ''),
)
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/types/app/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ export interface AppConfigBuild {
*
* @default true
*/
shouldPreload?: ((file: string, type: string) => boolean) | boolean
shouldPreload?: boolean | ((file: string, type: string) => boolean)

/**
* Determine what resource files should be prefetched. Use boolean value to
* totally enable / disable.
*
* @default true
*/
shouldPrefetch?: ((file: string, type: string) => boolean) | boolean
shouldPrefetch?: boolean | ((file: string, type: string) => boolean)

/**
* Specify the path of the HTML template to be used for build
Expand All @@ -95,7 +95,7 @@ export interface AppConfigBuild {
/**
* Vuepress app config
*/
export type AppConfig = AppConfigCommon & AppConfigDev & AppConfigBuild
export type AppConfig = AppConfigBuild & AppConfigCommon & AppConfigDev

/**
* Vuepress app options
Expand Down
2 changes: 1 addition & 1 deletion packages/markdown/src/plugins/emojiPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { full as emojiPlugin } from 'markdown-it-emoji'
import type { Options } from 'markdown-it-emoji'
import { full as emojiPlugin } from 'markdown-it-emoji'

export type EmojiPluginOptions = Options
export { emojiPlugin }
20 changes: 10 additions & 10 deletions packages/markdown/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ export type Markdown = MarkdownIt
export type { MarkdownSfcBlocks }

export interface MarkdownOptions extends Options {
anchor?: false | AnchorPluginOptions
assets?: false | AssetsPluginOptions
anchor?: AnchorPluginOptions | false
assets?: AssetsPluginOptions | false
component?: false
emoji?: false | EmojiPluginOptions
frontmatter?: false | FrontmatterPluginOptions
headers?: false | HeadersPluginOptions
emoji?: EmojiPluginOptions | false
frontmatter?: FrontmatterPluginOptions | false
headers?: HeadersPluginOptions | false
title?: false
importCode?: false | ImportCodePluginOptions
links?: false | LinksPluginOptions
sfc?: false | SfcPluginOptions
importCode?: ImportCodePluginOptions | false
links?: LinksPluginOptions | false
sfc?: SfcPluginOptions | false
slugify?: MarkdownSlugifyFunction
toc?: false | TocPluginOptions
vPre?: false | VPrePluginOptions
toc?: TocPluginOptions | false
vPre?: VPrePluginOptions | false
/**
* @deprecated This feature has been removed. Please use `@vuepress/plugin-prismjs` or `@vuepress/plugin-shiki` instead.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/markdown/tests/plugins/linksPlugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MarkdownIt from 'markdown-it'
import { describe, expect, it } from 'vitest'
import { linksPlugin } from '../../src/index.js'
import type { MarkdownEnv } from '../../src/index.js'
import { linksPlugin } from '../../src/index.js'

describe('@vuepress/markdown > plugins > linksPlugin', () => {
describe('external links', () => {
Expand Down
62 changes: 31 additions & 31 deletions packages/markdown/tests/plugins/vPrePlugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import MarkdownIt from 'markdown-it'
import { describe, expect, it, vi } from 'vitest'
import { vPrePlugin } from '../../src/index.js'

const codeFence = '```'
const CODE_FENCE = '```'

describe('@vuepress/markdown > plugins > vPrePlugin', () => {
describe('plugin options', () => {
const source = `\
${codeFence}js
${CODE_FENCE}js
const a = 1
${codeFence}
${CODE_FENCE}
\`inline\`
`
Expand Down Expand Up @@ -40,33 +40,33 @@ ${codeFence}

describe(':v-pre / :no-v-pre', () => {
const source = `\
${codeFence}js:v-pre
${CODE_FENCE}js:v-pre
const a = 1
${codeFence}
${CODE_FENCE}
${codeFence}js:no-v-pre
${CODE_FENCE}js:no-v-pre
const a = 1
${codeFence}
${CODE_FENCE}
${codeFence}js{1,2}:v-pre
${CODE_FENCE}js{1,2}:v-pre
const a = 1
${codeFence}
${CODE_FENCE}
${codeFence}js{1,2}:no-v-pre
${CODE_FENCE}js{1,2}:no-v-pre
const a = 1
${codeFence}
${CODE_FENCE}
${codeFence}js:other-syntax:v-pre
${CODE_FENCE}js:other-syntax:v-pre
const a = 1
${codeFence}
${CODE_FENCE}
${codeFence}js:other-syntax:no-v-pre
${CODE_FENCE}js:other-syntax:no-v-pre
const a = 1
${codeFence}
${CODE_FENCE}
${codeFence}js
${CODE_FENCE}js
const a = 1
${codeFence}
${CODE_FENCE}
`
it('should work if `block` is enabled by default', () => {
const md = MarkdownIt().use(vPrePlugin)
Expand All @@ -83,33 +83,33 @@ ${codeFence}

describe('syntax highlighting', () => {
const source = `\
${codeFence}js:v-pre
${CODE_FENCE}js:v-pre
const a = 1
${codeFence}
${CODE_FENCE}
${codeFence}js:no-v-pre
${CODE_FENCE}js:no-v-pre
const a = 1
${codeFence}
${CODE_FENCE}
${codeFence}js{1,2}:v-pre
${CODE_FENCE}js{1,2}:v-pre
const a = 1
${codeFence}
${CODE_FENCE}
${codeFence}js{1,2}:no-v-pre
${CODE_FENCE}js{1,2}:no-v-pre
const a = 1
${codeFence}
${CODE_FENCE}
${codeFence}js:other-syntax:v-pre
${CODE_FENCE}js:other-syntax:v-pre
const a = 1
${codeFence}
${CODE_FENCE}
${codeFence}js:other-syntax:no-v-pre
${CODE_FENCE}js:other-syntax:no-v-pre
const a = 1
${codeFence}
${CODE_FENCE}
${codeFence}js
${CODE_FENCE}js
const a = 1
${codeFence}
${CODE_FENCE}
`
it('should work highlighted code is wrapped with `<pre>`', () => {
const highlight = vi.fn(
Expand Down
10 changes: 5 additions & 5 deletions packages/shared/src/types/head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ export type HeadConfig =
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head
*/
export type HeadTag = HeadTagNonEmpty | HeadTagEmpty
export type HeadTag = HeadTagEmpty | HeadTagNonEmpty

/**
* Non-empty tags in `<head>`
*/
export type HeadTagNonEmpty =
| 'title'
| 'style'
| 'script'
| 'noscript'
| 'script'
| 'style'
| 'template'
| 'title'

/**
* Empty tags in `<head>`
Expand All @@ -30,4 +30,4 @@ export type HeadTagEmpty = 'base' | 'link' | 'meta' | 'script'
/**
* Attributes to be set for tags in `<head>`
*/
export type HeadAttrsConfig = Record<string, string | boolean>
export type HeadAttrsConfig = Record<string, boolean | string>
2 changes: 1 addition & 1 deletion packages/shared/tests/dedupeHead.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, it } from 'vitest'
import { dedupeHead } from '../src/index.js'
import type { HeadConfig } from '../src/index.js'
import { dedupeHead } from '../src/index.js'

it('should dedupe head correctly', () => {
const head: HeadConfig[] = [
Expand Down

0 comments on commit d85018d

Please sign in to comment.