Skip to content

Commit

Permalink
fix(mw/config): parser config for MoegirlPedia
Browse files Browse the repository at this point in the history
close #19
  • Loading branch information
bhsd-harry committed May 17, 2024
1 parent 96c4c83 commit 3aa9c3c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,12 @@
"parserOptions": {
"project": "./mw/tsconfig.json"
}
},
{
"files": "test/*.ts",
"parserOptions": {
"project": "./test/tsconfig.json"
}
}
],
"settings": {
Expand Down
24 changes: 12 additions & 12 deletions dist/main.min.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions mw/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const getMwConfig = async (): Promise<MwConfig> => {
const parserConfig: Config = await (await fetch(
`${CDN}/npm/[email protected]/config/moegirl.json`,
)).json();
mw.config.set('wikilintConfig', parserConfig);
setObject('wikilintConfig', parserConfig);
config = getStaticMwConfig(parserConfig);
} else {
// 以下情形均需要发送API请求
Expand Down Expand Up @@ -147,10 +147,11 @@ export const getMwConfig = async (): Promise<MwConfig> => {
* @param mwConfig
*/
export const getParserConfig = (minConfig: Config, mwConfig: MwConfig): Config => {
if (mw.config.exists('wikilintConfig')) {
return mw.config.get('wikilintConfig') as Config;
let config: Config | null = getObject('wikilintConfig');
if (config) {
return config;
}
const config: Config = {
config = {
...minConfig,
ext: Object.keys(mwConfig.tags),
namespaces: mw.config.get('wgFormattedNamespaces'),
Expand All @@ -162,6 +163,9 @@ export const getParserConfig = (minConfig: Config, mwConfig: MwConfig): Config =
protocol: mwConfig.urlProtocols.replace(/\|\\?\/\\?\//u, ''),
redirection: mwConfig.redirection || minConfig.redirection,
};
if (location.hostname.endsWith('.moegirl.org.cn')) {
config.html[2].push('img');
}
[config.parserFunction[0]] = mwConfig.functionSynonyms;
if (mw.loader.getState('ext.CodeMirror') === null) {
for (const [key, val] of Object.entries(mwConfig.functionSynonyms[0])) {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"/i18n/",
"/dist/*.js",
"/dist/*.d.ts",
"!/dist/gh-page.d.ts",
"!/dist/*-page.d.ts",
"!/dist/parserTests.js",
"/mediawiki.css"
],
"browser": "dist/main.min.js",
Expand All @@ -33,7 +34,7 @@
"build": "npm run build:core && npm run build:mw && npm run build:test",
"diff": "git diff --ignore-all-space --color-moved",
"diff:stat": "f() { git diff --stat --ignore-all-space --color=always $1 $2 -- . ':!dist/' ':!.github/'; }; f",
"lint:ts": "tsc --noEmit && tsc --project mw/tsconfig.json --noEmit && eslint --cache .",
"lint:ts": "tsc --noEmit && tsc --project mw/tsconfig.json --noEmit && tsc --project test/tsconfig.json --noEmit && eslint --cache .",
"lint:css": "stylelint *.css",
"lint": "npm run lint:ts && npm run lint:css",
"server": "npm run test:end; http-server .. -c-1 --cors &",
Expand Down
9 changes: 9 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"include": [
"*.ts"
],
"compilerOptions": {
"resolveJsonModule": true
}
}
4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"include": [
"src/*.ts",
"test/*.ts"
"src/*.ts"
],
"compilerOptions": {
"target": "ES2018",
"module": "CommonJS",
"resolveJsonModule": true,
"declaration": true,
"outDir": "dist",
"alwaysStrict": true,
Expand Down

0 comments on commit 3aa9c3c

Please sign in to comment.