Skip to content

Commit

Permalink
Merge branch 'main' into l10n/main
Browse files Browse the repository at this point in the history
  • Loading branch information
its-miroma authored Dec 8, 2024
2 parents 121070e + acbc6dd commit 46c39e5
Show file tree
Hide file tree
Showing 121 changed files with 1,064 additions and 850 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
node-version-file: ".nvmrc"
- run: npm i
- run: npm run build

Expand All @@ -22,8 +22,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'microsoft'
java-version: '21'
distribution: "microsoft"
java-version: "21"
- run: ./gradlew build --stacktrace --warning-mode fail
working-directory: ./reference
- run: ./gradlew runDatagen --stacktrace --warning-mode fail
Expand All @@ -32,4 +32,4 @@ jobs:
if: ${{ failure() }}
with:
reports: |
reference/**/build/reports/checkstyle/*.xml
reference/**/build/reports/checkstyle/*.xml
8 changes: 4 additions & 4 deletions .github/workflows/markdownlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
branches:
- main
paths:
- '**/*.md'
- '!README.md'
- '!translated/**'
- '!versions/*/translated/**'
- "**/*.md"
- "!README.md"
- "!translated/**"
- "!versions/*/translated/**"
workflow_dispatch: # Manual run

concurrency:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
node-version-file: ".nvmrc"
- run: npm i
- run: npm run build
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './.vitepress/dist'
path: "./.vitepress/dist"

deploy:
environment:
Expand All @@ -40,4 +40,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
uses: actions/deploy-pages@v4
70 changes: 61 additions & 9 deletions .markdownlint-cli2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ config:
style: atx
MD004:
style: dash
MD007:
indent: 2
MD009:
br_spaces: 0
MD013: false
Expand All @@ -21,7 +19,6 @@ config:
MD033: false
MD035:
style: ---
MD044: false
MD046:
style: fenced
MD048:
Expand All @@ -44,11 +41,18 @@ config:
rules:
- name: missing-heading-anchor
message: "Add anchors to headings. Use lowercase characters, numbers and dashes"
searchPattern: "/^#+.*$(?<!\\{#[a-z0-9-]+\\})/gm"
information: https://vitepress.dev/guide/markdown#header-anchors
searchPattern: "/^#+ .*$(?<!\\{#[a-z0-9-]+\\})/gm"
searchScope: text
- name: missing-space-before-anchor
message: "Add a space before the heading's anchor."
information: https://vitepress.dev/guide/markdown#header-anchors
searchPattern: "/^(#+ .*)(?<! )(\\{#[a-z0-9-]+\\})$/gm"
replace: "$1 $2"
searchScope: text
- name: no-absolute-links
message: "Don't use absolute links"
searchPattern: "/\\[.*?\\]\\(/(?!assets|public|reference).*?\\)/g"
searchPattern: "/\\[[^\\]]*\\]\\(/(?!assets|public|reference)[^\\)]*\\)/g"
searchScope: text
- name: no-curly-quotes
message: "Don't use curly quotes"
Expand All @@ -57,17 +61,65 @@ config:
searchScope: text
- name: no-file-extension-in-links
message: "Don't add the file extension to links"
searchPattern: "/\\[(.*?)\\]\\((.*?)\\.(?:md|html)((?:#[a-z0-9-]+)?)\\)/g"
replace: "[$1]($2$3)"
information: https://vitepress.dev/guide/routing#linking-between-pages
searchPattern: "/(\\[[^\\]]*\\])\\(([^\\)]*)\\.(?:md|html)((?:#[a-z0-9-]+)?)\\)/g"
replace: "$1($2$3)"
searchScope: text
- name: no-github-flavored-alerts
message: "Don't use GitHub-favored Alerts"
information: https://vitepress.dev/guide/markdown#custom-containers
searchPattern:
- "/^> \\[!NOTE\\]/gm"
- "/^> \\[!TIP\\]/gm"
- "/^> \\[!IMPORTANT\\]/gm"
- "/^> \\[!WARNING\\]/gm"
- "/^> \\[!CAUTION\\]/gm"
replace:
- "::: info"
- "::: tip"
- "::: warning IMPORTANT"
- "::: warning"
- "::: danger"
searchScope: text
- name: no-images-in-text
message: "Don't place images in text"
searchPattern: "/(?:(?<!^)!\\[[^\\]]*\\]\\([^\\)]*\\).*$)|(?:^!\\[[^\\]]*\\]\\([^\\)]*\\)(?!$))/gm"
searchScope: text
- name: no-invalid-containers
message: "Don't use invalid containers"
information: https://vitepress.dev/guide/markdown#custom-containers
searchPattern: "/^::: (?!(?:info|tip|warning|danger|details|raw|code-group|v-pre)(?: |$))/gm"
replace: "::: info "
searchScope: text
- name: no-links-to-public
message: "Don't add /public to links"
information: https://vitepress.dev/guide/asset-handling#the-public-directory
searchPattern: "/(\\[[^\\]]*\\]\\()/public([^\\)]*\\))/g"
replace: "$1$2"
searchScope: text
- name: no-multiple-spaces
message: "Don't use multiple spaces"
searchPattern: "/(?<!\\n| ) +(?! |\\|)/g"
searchPattern: "/(?<!\\n|\\|| ) +(?! |\\|)/g"
replace: " "
searchScope: text
- name: no-nbsp
message: "Don't use no-break spaces"
searchPattern: "/\\xa0/gu"
replace: " "
searchScope: all
- name: no-padding-for-keybinds
message: "Don't put spaces around pluses in keybinds"
searchPattern: "/(<\\/kbd *>)(?:(?: +\\+ *)|(?:\\+ +))(<kbd[^>]*>)/g"
replace: "$1+$2"
searchScope: text
- name: no-punctuation-after-images
message: "Don't place punctuation after images"
searchPattern: "/^(!\\[[^\\]]*\\]\\([^\\)]*\\))[.,:;?!]+/gm"
replace: "$1"
searchScope: text
- name: no-punctuation-in-links
message: "Don't place punctuation inside of links"
searchPattern: "/(?<!@)\\[(.*?)([.,:;?!]+)\\]\\((.*?)\\)/g"
searchPattern: "/(?<!@)\\[([^\\]]*)([.,:;?!]+)\\]\\(([^\\)]*)\\)/g"
replace: "[$1]($3)$2"
searchScope: text
- name: no-trailing-whitespace
Expand Down
31 changes: 10 additions & 21 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import defineVersionedConfig from "vitepress-versioning-plugin";

import { loadLocales, processExistingEntries } from "./i18n";
import { transformItems, transformPageData } from "./transform";
import { DefaultTheme } from "vitepress";

// https://vitepress.dev/reference/site-config
// https://www.npmjs.com/package/vitepress-versioning-plugin
Expand All @@ -25,19 +24,13 @@ export default defineVersionedConfig(
md.use(snippetPlugin);
},
languages: [
(async () => {
const mcfunctionLanguage = (await import("syntax-mcfunction/mcfunction.tmLanguage.json", {
with: {
type: "json"
}
}) as any).default

mcfunctionLanguage.name = 'mcfunction';
return mcfunctionLanguage;
}),
async () =>
await import("syntax-mcfunction/mcfunction.tmLanguage.json", {
with: { type: "json" },
}).then((lang) => ({ ...(lang.default as any), name: "mcfunction" })),
],
async shikiSetup(shiki) {
await shiki.loadTheme('github-light', 'github-dark');
await shiki.loadTheme("github-light", "github-dark");
},
lineNumbers: true,
math: true,
Expand All @@ -56,7 +49,7 @@ export default defineVersionedConfig(

themeConfig: {
search: {
provider: "local"
provider: "local",
},
},

Expand All @@ -68,15 +61,11 @@ export default defineVersionedConfig(
localePrefix: "translated",
},
sidebars: {
sidebarContentProcessor(sidebar: DefaultTheme.SidebarMulti) {
return processExistingEntries(sidebar);
},
}
sidebarContentProcessor: processExistingEntries,
sidebarUrlProcessor: (url: string, version: string) =>
url.startsWith("/") ? `/${version}${url}` : url,
},
},

build: {
sourcemap: true,
}
},
__dirname
);
66 changes: 48 additions & 18 deletions .vitepress/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { existsSync, readdirSync, readFileSync } from "fs";
import { resolve } from "path/posix";
import { DefaultTheme, LocaleConfig } from "vitepress";
import { LocaleConfig } from "vitepress";
import { Versioned } from "vitepress-versioning-plugin";

import DevelopSidebar from "./sidebars/develop";
import PlayersSidebar from "./sidebars/players";
Expand Down Expand Up @@ -34,9 +35,13 @@ export const getWebsiteResolver = (localeFolder: string) =>
export const getSidebarResolver = (localeFolder: string) =>
getTranslationsResolver(localeFolder, "sidebar_translations.json");

export function processExistingEntries(sidebar: DefaultTheme.SidebarMulti): DefaultTheme.SidebarMulti {
export function processExistingEntries(
sidebar: Versioned.Sidebar
): Versioned.Sidebar {
// Get locales from __dirname/../translated/* folder names.
const localeFolders = readdirSync(resolve(__dirname, "..", "translated"), { withFileTypes: true })
const localeFolders = readdirSync(resolve(__dirname, "..", "translated"), {
withFileTypes: true,
})
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);

Expand All @@ -45,7 +50,11 @@ export function processExistingEntries(sidebar: DefaultTheme.SidebarMulti): Defa

const keys = Object.keys(sidebar);
const versionedEntries = keys.filter((key) => {
return !key.includes("/players") && !key.includes("/develop") && localeFolders.some((locale) => key.includes(locale));
return (
!key.includes("/players") &&
!key.includes("/develop") &&
localeFolders.some((locale) => key.includes(locale))
);
});

const versionsMet = new Set<string>();
Expand All @@ -57,21 +66,35 @@ export function processExistingEntries(sidebar: DefaultTheme.SidebarMulti): Defa

versionsMet.add(version);

const playersToCopy = JSON.parse(JSON.stringify(sidebar[`/${version}/players/`]));
const developToCopy = JSON.parse(JSON.stringify(sidebar[`/${version}/develop/`]));
const playersToCopy = JSON.parse(
JSON.stringify(sidebar[`/${version}/players/`])
);
const developToCopy = JSON.parse(
JSON.stringify(sidebar[`/${version}/develop/`])
);

sidebar[`/${locale}/${version}/players/`] = getLocalisedSidebar(playersToCopy, locale);
sidebar[`/${locale}/${version}/develop/`] = getLocalisedSidebar(developToCopy, locale);
sidebar[`/${locale}/${version}/players/`] = getLocalisedSidebar(
playersToCopy,
locale
);
sidebar[`/${locale}/${version}/develop/`] = getLocalisedSidebar(
developToCopy,
locale
);

// Delete the original entry.
delete sidebar[entry];
}

for (const version of versionsMet) {
// @ts-ignore
sidebar[`/${version}/players/`] = getLocalisedSidebar(sidebar[`/${version}/players/`], "root");
// @ts-ignore
sidebar[`/${version}/develop/`] = getLocalisedSidebar(sidebar[`/${version}/develop/`], "root");
sidebar[`/${version}/players/`] = getLocalisedSidebar(
sidebar[`/${version}/players/`] as Fabric.SidebarItem[],
"root"
);
sidebar[`/${version}/develop/`] = getLocalisedSidebar(
sidebar[`/${version}/develop/`] as Fabric.SidebarItem[],
"root"
);
}

return sidebar;
Expand Down Expand Up @@ -160,7 +183,6 @@ function generateTranslatedThemeConfig(localeCode: string): Fabric.ThemeConfig {
if (localeCode === "root") {
return null;
} else {
// @ts-ignore
return crowdinOverrides[localeCode] ?? localeCode.split("_")[0];
}
};
Expand All @@ -187,6 +209,10 @@ function generateTranslatedThemeConfig(localeCode: string): Fabric.ThemeConfig {
prev: websiteResolver("footer.prev"),
},

download: {
text: websiteResolver("download"),
},

editLink: {
pattern: "https://github.com/FabricMC/fabric-docs/edit/main/:path",
text: websiteResolver("github_edit"),
Expand Down Expand Up @@ -226,9 +252,8 @@ function generateTranslatedThemeConfig(localeCode: string): Fabric.ThemeConfig {
],
},
{
// TODO: Allow custom component to have i18n translations for mobile navigation bar.
component: "VersionSwitcher"
}
component: "VersionSwitcher",
},
],

notFound: {
Expand Down Expand Up @@ -308,6 +333,11 @@ function generateTranslatedThemeConfig(localeCode: string): Fabric.ThemeConfig {
},
],

version: {
reminder: websiteResolver("version.reminder"),
switcher: websiteResolver("version.switcher"),
},

versionSwitcher: false,
};
}
Expand Down Expand Up @@ -359,8 +389,8 @@ export function loadLocales(dirname: string): LocaleConfig<Fabric.ThemeConfig> {
language === region.toLowerCase()
? localeNameInEnglish.of(language)!
: localeNameInEnglish.of(language)! +
" - " +
regionNameInEnglish.of(region);
" - " +
regionNameInEnglish.of(region);

const localisedName =
localeNameInLocale.of(language)![0].toUpperCase() +
Expand Down
Loading

0 comments on commit 46c39e5

Please sign in to comment.