diff --git a/README.md b/README.md index 59c9993d..7ea3cf05 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,21 @@ Join our community chats to stay updated and collaborate: Contributing is not just encouraged; it's easy! +### Suggestions and new ideas + If you've solved a challenging problem or found a better way to explain a complex topic, share it: — Got an idea? [Open an Issue](https://github.com/tact-lang/tact-docs/issues/new/choose). — Ready to contribute? [Set up your Development Environment](#set-up-your-development-environment). +## Translations + +At the moment, only Chinese translations are accepted. + +To add a new page, copy the existing one in English and add a `.zh` postfix after its name. For example, if the page is called `types.mdx`, copy it into the `types.zh.mdx` . Then, add the relevant info into the `_meta.zh.js` file (navigation on the left), which should be in the same folder as the modified page. + +Note, that you should **not** modify the folder structure or copy-paste folders. + ## Set Up Your Development Environment Before you submit your amazing contributions, ensure they work seamlessly. diff --git a/configs-i18n/i18n-next.config.js b/configs-i18n/i18n-next.config.js new file mode 100644 index 00000000..4eec57e2 --- /dev/null +++ b/configs-i18n/i18n-next.config.js @@ -0,0 +1,78 @@ +import { getHighlighter, BUNDLED_LANGUAGES } from 'shiki'; +import nextra from 'nextra'; +import fs from 'fs'; + +const grammar_tact = JSON.parse(fs.readFileSync('./grammars/grammar-tact.json', 'utf-8')); +const grammar_func = JSON.parse(fs.readFileSync('./grammars/grammar-func.json', 'utf-8')); +const grammar_ohm = JSON.parse(fs.readFileSync('./grammars/grammar-ohm.json', 'utf-8')); + +const rehypePrettyCodeOptions = { + getHighlighter: options => { + return getHighlighter({ + ...options, + langs: [ + ...BUNDLED_LANGUAGES, + { + id: 'tact', + scopeName: 'source.tact', + grammar: grammar_tact, + aliases: ['tact'], + }, + { + id: 'func', + scopeName: 'source.func', + grammar: grammar_func, + aliases: ['func'], + }, + { + id: 'ohm', + scopeName: 'source.ohm', + grammar: grammar_ohm, + aliases: ['ohm'], + }, + ], + }); + }, +}; + +/** + * @type {import('next').NextConfig} + */ +const withNextra = nextra({ + theme: 'nextra-theme-docs', + themeConfig: './theme.config.jsx', + mdxOptions: { + rehypePrettyCodeOptions + }, + latex: true, + defaultShowCopyCode: true +}); + +/** + * @type {import('next').NextConfig} + */ +export default withNextra({ + output: 'export', + images: { + unoptimized: true + }, + i18n: { + locales: ['default', 'en', 'zh'], + defaultLocale: 'default', + // localeDetection: false, + }, + webpack(config) { + const allowedSvgRegex = /components\/icons\/.+\.svg$/ + + const fileLoaderRule = config.module.rules.find(rule => + rule.test?.test?.('.svg') + ) + fileLoaderRule.exclude = allowedSvgRegex + + config.module.rules.push({ + test: allowedSvgRegex, + use: ['@svgr/webpack'] + }) + return config + }, +}); diff --git a/configs-i18n/i18n-theme.config.jsx b/configs-i18n/i18n-theme.config.jsx new file mode 100644 index 00000000..e14c8cef --- /dev/null +++ b/configs-i18n/i18n-theme.config.jsx @@ -0,0 +1,98 @@ +import { useRouter } from 'next/router' +import { DocsThemeConfig } from 'nextra-theme-docs' + +/** + * @type {DocsThemeConfig} + */ +const config = { + logo: ( + + + + + + + + + + + + + + + + + + + + + ), + darkMode: true, + nextThemes: { + defaultTheme: 'dark', + }, + project: { + link: 'https://github.com/tact-lang/tact-docs', + }, + docsRepositoryBase: 'https://github.com/tact-lang/tact-docs/edit/main/', + i18n: [ + { locale: 'en', text: 'English' }, + { locale: 'zh', text: '中文' }, + ], + sidebar: { + autoCollapse: true, + defaultMenuCollapseLevel: 1, + toggleButton: true, + }, + feedback: { + content: null + }, + // editLink: { + // text: function useText() { + // const { locale } = useRouter() + // return { + // 'en': 'Edit this page on GitHub', + // // 'zh': '在 GitHub 上编辑此页', + // }[locale ?? "en"] + // } + // }, + footer: { + text: + CC BY 4.0, Tact Software Foundation + , + }, + toc: { + backToTop: true, + }, + useNextSeoProps() { + return { + titleTemplate: '%s – Tact' + } + }, + head: () => ( + <> + + + + + + + + + +