Skip to content

Commit

Permalink
feat: improve compact code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Nov 25, 2023
1 parent f7540cd commit 13a1479
Show file tree
Hide file tree
Showing 70 changed files with 569 additions and 902 deletions.
6 changes: 3 additions & 3 deletions docs/photo-swipe/src/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ Locales config for photo-swipe plugin.

## Client Config

### definePhotoSwipeOptions
### definePhotoSwipeConfig

Options passed to [`photo-swipe`](http://photoswipe.com/)

```ts
// .vuepress/client.ts
import { definePhotoSwipeOptions } from "vuepress-plugin-photo-swipe/client";
import { definePhotoSwipeConfig } from "vuepress-plugin-photo-swipe/client";

definePhotoSwipeOptions({
definePhotoSwipeConfig({
// set photoswipe options here
});

Expand Down
6 changes: 3 additions & 3 deletions docs/photo-swipe/src/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ By default, the plugin will select images according to the default theme's selec

## Customize PhotoSwipe Options

You can pass options to [`photo-swipe`](http://photoswipe.com/) by importing and calling `definePhotoSwipeOptions` in client config file:
You can pass options to [`photo-swipe`](http://photoswipe.com/) by importing and calling `definePhotoSwipeConfig` in client config file:

```ts
// .vuepress/client.ts
import { defineClientConfig } from "@vuepress/client";
import { definePhotoSwipeOptions } from "vuepress-plugin-photo-swipe/client";
import { definePhotoSwipeConfig } from "vuepress-plugin-photo-swipe/client";

definePhotoSwipeOptions({
definePhotoSwipeConfig({
// photoswipe options here
});

Expand Down
6 changes: 3 additions & 3 deletions docs/photo-swipe/src/zh/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ Photo Swipe 插件的国际化配置。

## 客户端配置

### definePhotoSwipeOptions
### definePhotoSwipeConfig

传递给 [`photo-swipe`](http://photoswipe.com/) 的额外选项。

```ts
// .vuepress/client.ts
import { definePhotoSwipeOptions } from "vuepress-plugin-photo-swipe/client";
import { definePhotoSwipeConfig } from "vuepress-plugin-photo-swipe/client";

definePhotoSwipeOptions({
definePhotoSwipeConfig({
// 在此设置 photoswipe 选项
});

Expand Down
6 changes: 3 additions & 3 deletions docs/photo-swipe/src/zh/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ icon: lightbulb

## 自定义 PhotoSwipe 选项

你可以通过在客户端配置文件中导入和调用 `definePhotoSwipeOptions` 来将选项传递给 [`photo-swipe`](http://photoswipe.com/)
你可以通过在客户端配置文件中导入和调用 `definePhotoSwipeConfig` 来将选项传递给 [`photo-swipe`](http://photoswipe.com/)

```ts
// .vuepress/client.ts
import { defineClientConfig } from "@vuepress/client";
import { definePhotoSwipeOptions } from "vuepress-plugin-photo-swipe/client";
import { definePhotoSwipeConfig } from "vuepress-plugin-photo-swipe/client";

definePhotoSwipeOptions({
definePhotoSwipeConfig({
// 在此设置 photoswipe 选项
});

Expand Down
40 changes: 40 additions & 0 deletions packages/auto-catalog/src/node/compact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { colors } from "@vuepress/utils";
import { createConverter } from "vuepress-shared/node";

import type { AutoCatalogOptions } from "./options.js";

/** @deprecated */
export const convertOptions = (
options: AutoCatalogOptions & Record<string, unknown>,
): void => {
const { deprecatedLogger, droppedLogger } = createConverter("auto-catalog");

deprecatedLogger({
options,
old: "getTitle",
new: "titleGetter",
});
deprecatedLogger({
options,
old: "getIcon",
new: "iconGetter",
});
deprecatedLogger({
options,
old: "getOrder",
new: "orderGetter",
});
deprecatedLogger({
options,
old: "getIndex",
new: "shouldIndex",
});

droppedLogger({
options,
old: "iconComponent",
msg: `please use ${colors.magenta(
"defineAutoCatalogIconComponent",
)} in client config file.`,
});
};
38 changes: 0 additions & 38 deletions packages/auto-catalog/src/node/compact/convert.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/auto-catalog/src/node/compact/index.ts

This file was deleted.

68 changes: 0 additions & 68 deletions packages/auto-catalog/src/node/compact/utils.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/auto-catalog/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "vuepress-shared/node";

import { generateCatalog, injectCatalogInformation } from "./autoCatalog.js";
import { convertOptions } from "./compact/index.js";
import { convertOptions } from "./compact.js";
import { locales as defaultLocales } from "./locales.js";
import type { AutoCatalogOptions } from "./options.js";
import { CLIENT_FOLDER, PLUGIN_NAME, logger } from "./utils.js";
Expand Down
23 changes: 8 additions & 15 deletions packages/blog2/src/node/compact.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import { colors } from "@vuepress/utils";
import { createConverter } from "vuepress-shared/node";

import type { BlogOptions } from "./options.js";
import { logger } from "./utils.js";

/** @deprecated */
export const convertOptions = (
options: BlogOptions & {
/** @deprecated */
customElement?: (tagName: string) => boolean;
},
options: BlogOptions & Record<string, unknown>,
): void => {
// v2 changes
if ("customElement" in options) {
logger.warn(
`${colors.magenta(
"customElement",
)} is deprecated, please use ${colors.magenta("isCustomElement")}.`,
);
const { deprecatedLogger } = createConverter("blog2");

options["isCustomElement"] = options["customElement"];
}
deprecatedLogger({
options,
old: "customElements",
new: "isCustomElement",
});
};
68 changes: 3 additions & 65 deletions packages/comment2/src/node/compact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,14 @@ export const convertOptions = (
// v2 changes
if ("type" in options) {
logger.warn(
`${colors.magenta(
"iconComponent",
)} is deprecated, please use ${colors.magenta("provider")}.`,
`${colors.magenta("type")} is deprecated, please use ${colors.magenta(
"provider",
)}.`,
);
if (options["type"] === "waline") options.provider = "Waline";
else if (options["type"] === "giscus") options.provider = "Giscus";
else if (options["type"] === "twikoo") options.provider = "Twikoo";

delete options["type"];
}

// convert Waline options
if (options.provider === "Waline") {
[
// valine
["emojiCDN", "emoji"],
["emojiMaps", "emoji"],
["requiredFields", "requiredMeta"],
["visitor", "pageview"],
["langMode", "locale"],
["placeholder", "locale.placeholder"],

// waline v1
["anonymous", "login"],
["copyRight", "copyright"],
].forEach(([oldOptions, newOptions]) => {
if (oldOptions in options) {
logger.warn(
`"${colors.magenta(
oldOptions,
)}" is deprecated in @waline/client@v2, you should use "${colors.magenta(
newOptions,
)}" instead.`,
);

// @ts-ignore
delete options[oldOptions];
}
});

[
// valine
"region",
"appId",
"appKey",
"notify",
"verify",
"avatar",
"avatarForce",
"enableQQ",
"recordIP",
"serverURLs",

// waline v1
"avatarCDN",
"mathTagSupport",
"highlight",
"uploadImage",
"previewMath",
].forEach((option) => {
if (option in options) {
logger.error(
`"${colors.magenta(
option,
)}" is no longer supported in @waline/client@v2.`,
);

// @ts-expect-error
delete options[option];
}
});
}
};
Loading

0 comments on commit 13a1479

Please sign in to comment.