|
| 1 | +import path from 'node:path'; |
| 2 | +import { fileURLToPath } from 'node:url'; |
| 3 | + |
| 4 | +import type { PluginConfig, ThemeConfig } from '@docusaurus/types'; |
| 5 | +import { themes } from 'prism-react-renderer'; |
| 6 | +import rehypeKatex from 'rehype-katex'; |
| 7 | +import remarkMath from 'remark-math'; |
| 8 | + |
| 9 | +export const defaultLocale = 'en'; |
| 10 | + |
| 11 | +// A workaround for locale-specific values in the config |
| 12 | +// https://github.com/facebook/docusaurus/issues/4542#issuecomment-1434839071 |
| 13 | +export const currentLocale = String(process.env.DOCUSAURUS_CURRENT_LOCALE ?? defaultLocale); |
| 14 | +export const localePath = currentLocale === defaultLocale ? '' : currentLocale; |
| 15 | + |
| 16 | +export const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 17 | + |
| 18 | +export const cfPagesBranch = String(process.env.CF_PAGES_BRANCH); |
| 19 | + |
| 20 | +// https://community.cloudflare.com/t/algorithm-to-generate-a-preview-dns-subdomain-from-a-branch-name/477633/2 |
| 21 | +export const getCloudflareSubdomain = (branchName: string) => |
| 22 | + branchName |
| 23 | + .replaceAll(/[^\da-z-]/g, '-') |
| 24 | + .slice(0, 28) |
| 25 | + .replace(/^-|-$/, ''); |
| 26 | + |
| 27 | +export const { dracula } = themes; |
| 28 | + |
| 29 | +export const addAliasPlugin: PluginConfig = () => ({ |
| 30 | + name: 'add-alias-plugin', |
| 31 | + configureWebpack: () => ({ |
| 32 | + resolve: { |
| 33 | + alias: { |
| 34 | + '@components': path.resolve(__dirname, './src/components'), |
| 35 | + '@mdx-components': path.resolve(__dirname, './src/mdx-components'), |
| 36 | + '@scss': path.resolve(__dirname, './src/scss'), |
| 37 | + }, |
| 38 | + }, |
| 39 | + }), |
| 40 | +}); |
| 41 | + |
| 42 | +export const injectHeadTagsPlugin: PluginConfig = () => ({ |
| 43 | + name: 'inject-head-tags-plugin', |
| 44 | + injectHtmlTags: () => ({ |
| 45 | + headTags: [ |
| 46 | + { |
| 47 | + tagName: 'script', |
| 48 | + innerHTML: ` |
| 49 | + var shouldTrack = |
| 50 | + window.location.hostname === 'logto.io' || window.location.hostname.endsWith('logto.io'); |
| 51 | + if (!shouldTrack) { |
| 52 | + console.warn('Not tracking because the hostname is not logto.io'); |
| 53 | + } |
| 54 | + `, |
| 55 | + }, |
| 56 | + { |
| 57 | + tagName: 'script', |
| 58 | + attributes: { |
| 59 | + src: 'https://akasha.logto.io/placebo/sabaean.js', |
| 60 | + defer: true, |
| 61 | + 'data-api': 'https://akasha.logto.io/placebo/eagan', |
| 62 | + 'data-domain': 'logto.io', |
| 63 | + }, |
| 64 | + }, |
| 65 | + { |
| 66 | + tagName: 'script', |
| 67 | + innerHTML: ` |
| 68 | + if (shouldTrack) { |
| 69 | + window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }; |
| 70 | + } |
| 71 | + `, |
| 72 | + }, |
| 73 | + { |
| 74 | + tagName: 'meta', |
| 75 | + attributes: { |
| 76 | + name: 'google-site-verification', |
| 77 | + content: '3EYzsnarDwG6zL2dlHvyC8ySVcV6Q3RGlvh7-bvhb2k', |
| 78 | + }, |
| 79 | + }, |
| 80 | + ], |
| 81 | + }), |
| 82 | +}); |
| 83 | + |
| 84 | +export const commonThemeConfig = { |
| 85 | + navbar: { |
| 86 | + logo: { |
| 87 | + alt: 'Logto Logo', |
| 88 | + src: 'img/logto.svg', |
| 89 | + srcDark: 'img/logto_dark.svg', |
| 90 | + href: new URL(localePath, 'https://logto.io/').href, |
| 91 | + }, |
| 92 | + }, |
| 93 | + footer: { |
| 94 | + logo: { |
| 95 | + alt: 'Logo', |
| 96 | + src: '/img/silverhand.svg', |
| 97 | + }, |
| 98 | + style: 'dark', |
| 99 | + links: [ |
| 100 | + { |
| 101 | + title: 'Developers', |
| 102 | + items: [ |
| 103 | + { label: 'Docs', to: '/' }, |
| 104 | + { label: 'Quick starts', to: '/quick-starts' }, |
| 105 | + { label: 'Integrations', to: '/integrations' }, |
| 106 | + { |
| 107 | + label: 'Account API', |
| 108 | + href: 'https://openapi.logto.io/group/endpoint-account-center', |
| 109 | + }, |
| 110 | + { |
| 111 | + label: 'Experience API', |
| 112 | + href: 'https://openapi.logto.io/group/endpoint-experience', |
| 113 | + }, |
| 114 | + { label: 'Management API', href: 'https://openapi.logto.io' }, |
| 115 | + { label: 'Build X with Y', href: 'pathname:///tutorials' }, |
| 116 | + ], |
| 117 | + }, |
| 118 | + { |
| 119 | + title: 'Resources', |
| 120 | + items: [ |
| 121 | + { label: 'Pricing', href: 'https://logto.io/pricing' }, |
| 122 | + { label: 'Blogs', href: 'https://blog.logto.io' }, |
| 123 | + { label: 'Auth Wiki', href: 'https://auth.wiki' }, |
| 124 | + { label: "What's new", href: 'https://blog.logto.io/categories/changelogs/#all' }, |
| 125 | + { label: 'YouTube', href: 'https://youtube.com/@logto-io' }, |
| 126 | + { label: 'GitHub', href: 'https://github.com/logto-io/logto' }, |
| 127 | + ], |
| 128 | + }, |
| 129 | + { |
| 130 | + title: 'Need help?', |
| 131 | + items: [ |
| 132 | + { |
| 133 | + label: 'Contact support', |
| 134 | + href: 'https://logto.io/contact', |
| 135 | + icon: 'email', |
| 136 | + hideExternalLinkIcon: true, |
| 137 | + }, |
| 138 | + { |
| 139 | + label: 'Open a GitHub issue', |
| 140 | + href: 'https://github.com/logto-io/logto/issues/new/choose', |
| 141 | + icon: 'github', |
| 142 | + hideExternalLinkIcon: true, |
| 143 | + }, |
| 144 | + { |
| 145 | + label: 'Request a new feature', |
| 146 | + href: 'https://logto.productlane.com/roadmap', |
| 147 | + icon: 'roadmap', |
| 148 | + hideExternalLinkIcon: true, |
| 149 | + }, |
| 150 | + { |
| 151 | + label: 'Ask the Discord community', |
| 152 | + href: 'https://discord.com/invite/UEPaF3j5e6', |
| 153 | + icon: 'discord', |
| 154 | + hideExternalLinkIcon: true, |
| 155 | + }, |
| 156 | + ], |
| 157 | + }, |
| 158 | + ], |
| 159 | + copyright: `Designed by Silverhand Inc.`, |
| 160 | + }, |
| 161 | + prism: { |
| 162 | + theme: dracula, |
| 163 | + darkTheme: dracula, |
| 164 | + additionalLanguages: [ |
| 165 | + 'swift', |
| 166 | + 'kotlin', |
| 167 | + 'groovy', |
| 168 | + 'java', |
| 169 | + 'php', |
| 170 | + 'json', |
| 171 | + 'bash', |
| 172 | + 'csharp', |
| 173 | + 'cshtml', |
| 174 | + 'json5', |
| 175 | + 'dart', |
| 176 | + 'ruby', |
| 177 | + 'erb', |
| 178 | + 'http', |
| 179 | + ], |
| 180 | + }, |
| 181 | + colorMode: { |
| 182 | + respectPrefersColorScheme: true, |
| 183 | + }, |
| 184 | + algolia: { |
| 185 | + appId: 'DE7QZWOVO6', |
| 186 | + apiKey: '4c64ad7f3b8622f59d8121dbac801337', |
| 187 | + indexName: 'logto', |
| 188 | + }, |
| 189 | +} satisfies ThemeConfig; |
| 190 | + |
| 191 | +export const commonI18n = { |
| 192 | + defaultLocale: 'en', |
| 193 | + locales: ['de', 'en', 'es', 'fr', 'ja', 'ko', 'pt-BR', 'zh-CN', 'zh-TW'], |
| 194 | + localeConfigs: { |
| 195 | + 'zh-CN': { label: '简体中文' }, |
| 196 | + 'zh-TW': { label: '繁體中文(台灣)' }, |
| 197 | + }, |
| 198 | +}; |
| 199 | + |
| 200 | +export const commonMarkdown = { |
| 201 | + mermaid: true, |
| 202 | +}; |
| 203 | + |
| 204 | +export const commonStylesheets = [ |
| 205 | + { |
| 206 | + href: 'https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.css', |
| 207 | + type: 'text/css', |
| 208 | + crossorigin: 'anonymous', |
| 209 | + }, |
| 210 | +]; |
| 211 | + |
| 212 | +export const classicPresetConfig = { |
| 213 | + sitemap: { |
| 214 | + changefreq: 'weekly', |
| 215 | + ignorePatterns: [ |
| 216 | + '/blog/**', |
| 217 | + // Some pages are not translated. Ignore them. |
| 218 | + '/*/terms', |
| 219 | + '/*/terms/**', |
| 220 | + '/*/about', |
| 221 | + '/*/about/**', |
| 222 | + ], |
| 223 | + }, |
| 224 | + docs: { |
| 225 | + routeBasePath: '/', |
| 226 | + breadcrumbs: true, |
| 227 | + sidebarPath: './src/sidebar/index.ts', |
| 228 | + editUrl: 'https://github.com/logto-io/docs/tree/master', |
| 229 | + editLocalizedFiles: true, |
| 230 | + // To enabled math formula rendering |
| 231 | + // See https://docusaurus.io/docs/markdown-features/math-equations#configuration |
| 232 | + remarkPlugins: [remarkMath], |
| 233 | + rehypePlugins: [rehypeKatex], |
| 234 | + }, |
| 235 | + theme: { |
| 236 | + customCss: './src/scss/custom.scss', |
| 237 | + }, |
| 238 | + svgr: { |
| 239 | + svgrConfig: { |
| 240 | + svgoConfig: { |
| 241 | + plugins: [ |
| 242 | + { |
| 243 | + name: 'preset-default', |
| 244 | + params: { |
| 245 | + overrides: { removeViewBox: false }, |
| 246 | + }, |
| 247 | + }, |
| 248 | + 'prefixIds', |
| 249 | + ], |
| 250 | + }, |
| 251 | + }, |
| 252 | + }, |
| 253 | +}; |
0 commit comments