Skip to content

Commit 9f34600

Browse files
authored
Merge pull request #1106 from logto-io/charles-configure-tutorial-only-build
feat: configure tutorial only build
2 parents a529fdb + 4655d76 commit 9f34600

10 files changed

+445
-301
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ cache
4141

4242
# generated files
4343
/static-localized/**/img/og
44+
_redirects

docs/_dummy.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- This is a dummy file needed when building the tutorial only builds.
2+
Since docusaurus requires at least one markdown file in the docs directory,
3+
we need this dummy file to make sure the build works. -->

docusaurus-common.ts

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
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+
};

docusaurus-tutorials.config.ts

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import 'dotenv/config';
2+
3+
import type { Config } from '@docusaurus/types';
4+
import { cond } from '@silverhand/essentials';
5+
6+
import {
7+
addAliasPlugin,
8+
cfPagesBranch,
9+
classicPresetConfig,
10+
commonI18n,
11+
commonMarkdown,
12+
commonStylesheets,
13+
commonThemeConfig,
14+
currentLocale,
15+
getCloudflareSubdomain,
16+
injectHeadTagsPlugin,
17+
} from './docusaurus-common';
18+
19+
// Supported locales for the "Build X with Y" tutorials
20+
const tutorialLocales = ['en', 'es', 'fr', 'ja'];
21+
22+
const getLogtoDocsUrl = () =>
23+
cfPagesBranch && cfPagesBranch !== 'master'
24+
? `https://${getCloudflareSubdomain(cfPagesBranch)}.logto-docs-tutorials.pages.dev/`
25+
: 'https://docs.logto.io/';
26+
27+
const config: Config = {
28+
title: 'Logto docs',
29+
url: getLogtoDocsUrl(),
30+
baseUrl: '/',
31+
onBrokenLinks: 'warn',
32+
onBrokenAnchors: 'warn',
33+
onBrokenMarkdownLinks: 'warn',
34+
favicon: '/img/favicon.ico',
35+
organizationName: 'logto-io',
36+
projectName: 'docs',
37+
38+
i18n: commonI18n,
39+
40+
customFields: {
41+
inkeepApiKey: process.env.INKEEP_API_KEY,
42+
},
43+
44+
staticDirectories: ['static', 'static-localized/' + currentLocale],
45+
46+
markdown: commonMarkdown,
47+
48+
trailingSlash: false,
49+
50+
presets: [
51+
[ 'classic', {
52+
...classicPresetConfig,
53+
docs: {
54+
...classicPresetConfig.docs,
55+
sidebarPath: undefined,
56+
exclude: ['*/**'],
57+
},
58+
} ],
59+
],
60+
61+
stylesheets: commonStylesheets,
62+
63+
themeConfig: {
64+
...commonThemeConfig,
65+
navbar: {
66+
...commonThemeConfig.navbar,
67+
items: [
68+
{
69+
to: 'https://docs.logto.io/introduction',
70+
position: 'left',
71+
label: 'Docs',
72+
},
73+
{
74+
to: 'https://docs.logto.io/quick-starts',
75+
position: 'left',
76+
label: 'Quick starts',
77+
},
78+
{
79+
to: 'https://docs.logto.io/integrations',
80+
position: 'left',
81+
label: 'Connectors',
82+
},
83+
{
84+
to: 'https://openapi.logto.io',
85+
position: 'left',
86+
label: 'API',
87+
},
88+
],
89+
},
90+
},
91+
92+
plugins: [
93+
addAliasPlugin,
94+
injectHeadTagsPlugin,
95+
'docusaurus-plugin-sass',
96+
cond(
97+
tutorialLocales.includes(currentLocale) && [
98+
'@docusaurus/plugin-content-blog',
99+
{
100+
/**
101+
* Required for any multi-instance plugin
102+
*/
103+
id: 'tutorials',
104+
/**
105+
* URL route for the blog section of your site.
106+
* *DO NOT* include a trailing slash.
107+
*/
108+
routeBasePath: 'tutorials',
109+
/**
110+
* Path to data on filesystem relative to site dir.
111+
*/
112+
path: './tutorial',
113+
blogSidebarCount: 0,
114+
showReadingTime: false,
115+
postsPerPage: 'ALL',
116+
},
117+
]
118+
),
119+
].filter(Boolean),
120+
themes: ['@docusaurus/theme-mermaid'],
121+
};
122+
123+
export default config;

0 commit comments

Comments
 (0)