Skip to content

Commit 71c29eb

Browse files
committed
refactor: test tutorial only build
1 parent 773fcd7 commit 71c29eb

File tree

4 files changed

+359
-1
lines changed

4 files changed

+359
-1
lines changed

docs/_dummy.mdx

Whitespace-only changes.

docusaurus-tutorial.config.ts

Lines changed: 346 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,346 @@
1+
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
import 'dotenv/config';
4+
5+
import type { ThemeConfig, Options } from '@docusaurus/preset-classic';
6+
import type { Config, PluginConfig } from '@docusaurus/types';
7+
import { themes } from 'prism-react-renderer';
8+
import rehypeKatex from 'rehype-katex';
9+
import remarkMath from 'remark-math';
10+
11+
import { cond } from '@silverhand/essentials';
12+
13+
const defaultLocale = 'en';
14+
15+
// Supported locales for the "Build X with Y" tutorials
16+
const tutorialLocales = ['en', 'es', 'fr', 'ja'];
17+
18+
// A workaround for locale-specific values in the config
19+
// https://github.com/facebook/docusaurus/issues/4542#issuecomment-1434839071
20+
const currentLocale = process.env.DOCUSAURUS_CURRENT_LOCALE ?? defaultLocale;
21+
const localePath = currentLocale === defaultLocale ? '' : currentLocale;
22+
23+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
24+
25+
const cfPagesBranch = process.env.CF_PAGES_BRANCH;
26+
27+
// https://community.cloudflare.com/t/algorithm-to-generate-a-preview-dns-subdomain-from-a-branch-name/477633/2
28+
const getCloudflareSubdomain = (branchName: string) =>
29+
branchName
30+
.replace(/[^a-z0-9-]/g, '-')
31+
.substring(0, 28)
32+
.replace(/^-|-$/, '');
33+
34+
const getLogtoDocsUrl = () =>
35+
cfPagesBranch && cfPagesBranch !== 'master'
36+
? `https://${getCloudflareSubdomain(cfPagesBranch)}.logto-docs.pages.dev/`
37+
: 'https://docs.logto.io/';
38+
39+
const { dracula } = themes;
40+
41+
const addAliasPlugin: PluginConfig = () => ({
42+
name: 'add-alias-plugin',
43+
configureWebpack: (config) => ({
44+
resolve: {
45+
alias: {
46+
'@components': path.resolve(__dirname, './src/components'),
47+
'@mdx-components': path.resolve(__dirname, './src/mdx-components'),
48+
'@scss': path.resolve(__dirname, './src/scss'),
49+
},
50+
},
51+
}),
52+
});
53+
54+
const injectHeadTagsPlugin: PluginConfig = () => ({
55+
name: 'inject-head-tags-plugin',
56+
injectHtmlTags: () => ({
57+
headTags: [
58+
{
59+
tagName: 'script',
60+
innerHTML: `
61+
var shouldTrack =
62+
window.location.hostname === 'logto.io' || window.location.hostname.endsWith('logto.io');
63+
if (!shouldTrack) {
64+
console.warn('Not tracking because the hostname is not logto.io');
65+
}
66+
`,
67+
},
68+
{
69+
tagName: 'script',
70+
attributes: {
71+
src: 'https://akasha.logto.io/placebo/sabaean.js',
72+
defer: true,
73+
'data-api': 'https://akasha.logto.io/placebo/eagan',
74+
'data-domain': 'logto.io',
75+
},
76+
},
77+
{
78+
tagName: 'script',
79+
innerHTML: `
80+
if (shouldTrack) {
81+
window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) };
82+
}
83+
`,
84+
},
85+
{
86+
tagName: 'meta',
87+
attributes: {
88+
name: 'google-site-verification',
89+
content: '3EYzsnarDwG6zL2dlHvyC8ySVcV6Q3RGlvh7-bvhb2k',
90+
},
91+
},
92+
],
93+
}),
94+
});
95+
96+
const config: Config = {
97+
title: 'Logto docs',
98+
url: getLogtoDocsUrl(),
99+
baseUrl: '/',
100+
onBrokenLinks: 'warn',
101+
onBrokenAnchors: 'warn',
102+
onBrokenMarkdownLinks: 'warn',
103+
favicon: '/img/favicon.ico',
104+
organizationName: 'logto-io', // Usually your GitHub org/user name.
105+
projectName: 'docs', // Usually your repo name.
106+
107+
i18n: {
108+
defaultLocale: 'en',
109+
locales: ['de', 'en', 'es', 'fr', 'ja', 'ko', 'pt-BR', 'zh-CN', 'zh-TW'],
110+
localeConfigs: {
111+
'zh-CN': { label: '简体中文' },
112+
'zh-TW': { label: '繁體中文(台灣)' },
113+
},
114+
},
115+
116+
customFields: {
117+
inkeepApiKey: process.env.INKEEP_API_KEY,
118+
buildTarget: process.env.BUILD_TARGET,
119+
},
120+
121+
staticDirectories: ['static', 'static-localized/' + currentLocale],
122+
123+
markdown: {
124+
mermaid: true,
125+
},
126+
127+
trailingSlash: false,
128+
129+
presets: [
130+
[
131+
'classic',
132+
{
133+
sitemap: {
134+
changefreq: 'weekly',
135+
ignorePatterns: [
136+
'/blog/**',
137+
// Some pages are not translated. Ignore them.
138+
'/*/terms',
139+
'/*/terms/**',
140+
'/*/about',
141+
'/*/about/**',
142+
],
143+
},
144+
docs: {
145+
routeBasePath: '/',
146+
breadcrumbs: true,
147+
editUrl: 'https://github.com/logto-io/docs/tree/master',
148+
editLocalizedFiles: true,
149+
// To enabled math formula rendering
150+
// See https://docusaurus.io/docs/markdown-features/math-equations#configuration
151+
remarkPlugins: [remarkMath],
152+
rehypePlugins: [rehypeKatex],
153+
exclude: [
154+
'*/**',
155+
],
156+
},
157+
theme: {
158+
customCss: './src/scss/custom.scss',
159+
},
160+
svgr: {
161+
svgrConfig: {
162+
svgoConfig: {
163+
plugins: [
164+
{
165+
name: 'preset-default',
166+
params: {
167+
overrides: { removeViewBox: false },
168+
},
169+
},
170+
'prefixIds',
171+
],
172+
},
173+
},
174+
},
175+
} satisfies Options,
176+
],
177+
],
178+
// To enabled math formula rendering
179+
// See https://docusaurus.io/docs/markdown-features/math-equations#configuration
180+
stylesheets: [
181+
{
182+
href: 'https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.css',
183+
type: 'text/css',
184+
crossorigin: 'anonymous',
185+
},
186+
],
187+
themeConfig: {
188+
navbar: {
189+
logo: {
190+
alt: 'Logto Logo',
191+
src: 'img/logto.svg',
192+
srcDark: 'img/logto_dark.svg',
193+
href: new URL(localePath, 'https://logto.io/').href,
194+
},
195+
items: [
196+
{
197+
to: 'https://docs.logto.io/introduction',
198+
position: 'left',
199+
label: 'Docs',
200+
},
201+
{
202+
to: 'https://docs.logto.io/quick-starts',
203+
position: 'left',
204+
label: 'Quick starts',
205+
},
206+
{
207+
to: 'https://docs.logto.io/integrations',
208+
position: 'left',
209+
label: 'Connectors',
210+
},
211+
{
212+
to: 'https://openapi.logto.io',
213+
position: 'left',
214+
label: 'API',
215+
},
216+
],
217+
},
218+
footer: {
219+
logo: {
220+
alt: 'Logo',
221+
src: '/img/silverhand.svg',
222+
},
223+
style: 'dark',
224+
links: [
225+
{
226+
title: 'Developers',
227+
items: [
228+
{ label: 'Docs', href: 'https://docs.logto.io' },
229+
{ label: 'Quick starts', href: 'https://docs.logto.io/quick-starts' },
230+
{ label: 'Integrations', href: 'https://docs.logto.io/integrations' },
231+
{
232+
label: 'Account API',
233+
href: 'https://openapi.logto.io/group/endpoint-account-center',
234+
},
235+
{
236+
label: 'Experience API',
237+
href: 'https://openapi.logto.io/group/endpoint-experience',
238+
},
239+
{ label: 'Management API', href: 'https://openapi.logto.io' },
240+
{ label: 'Build X with Y', href: 'pathname:///tutorial' },
241+
],
242+
},
243+
{
244+
title: 'Resources',
245+
items: [
246+
{ label: 'Pricing', href: 'https://logto.io/pricing' },
247+
{ label: 'Blogs', href: 'https://blog.logto.io' },
248+
{ label: 'Auth Wiki', href: 'https://auth.wiki' },
249+
{ label: "What's new", href: 'https://blog.logto.io/categories/changelogs/#all' },
250+
{ label: 'YouTube', href: 'https://youtube.com/@logto-io' },
251+
{ label: 'GitHub', href: 'https://github.com/logto-io/logto' },
252+
],
253+
},
254+
{
255+
title: 'Need help?',
256+
items: [
257+
{
258+
label: 'Contact support',
259+
href: 'https://logto.io/contact',
260+
icon: 'email',
261+
hideExternalLinkIcon: true,
262+
},
263+
{
264+
label: 'Open a GitHub issue',
265+
href: 'https://github.com/logto-io/logto/issues/new/choose',
266+
icon: 'github',
267+
hideExternalLinkIcon: true,
268+
},
269+
{
270+
label: 'Request a new feature',
271+
href: 'https://logto.productlane.com/roadmap',
272+
icon: 'roadmap',
273+
hideExternalLinkIcon: true,
274+
},
275+
{
276+
label: 'Ask the Discord community',
277+
href: 'https://discord.com/invite/UEPaF3j5e6',
278+
icon: 'discord',
279+
hideExternalLinkIcon: true,
280+
},
281+
],
282+
},
283+
],
284+
copyright: `Designed by Silverhand Inc.`,
285+
},
286+
prism: {
287+
theme: dracula,
288+
darkTheme: dracula,
289+
additionalLanguages: [
290+
'swift',
291+
'kotlin',
292+
'groovy',
293+
'java',
294+
'php',
295+
'json',
296+
'bash',
297+
'csharp',
298+
'cshtml',
299+
'json5',
300+
'dart',
301+
'ruby',
302+
'erb',
303+
'http',
304+
],
305+
},
306+
colorMode: {
307+
respectPrefersColorScheme: true,
308+
},
309+
algolia: {
310+
appId: 'DE7QZWOVO6',
311+
apiKey: '4c64ad7f3b8622f59d8121dbac801337',
312+
indexName: 'logto',
313+
},
314+
} satisfies ThemeConfig,
315+
plugins: [
316+
addAliasPlugin,
317+
injectHeadTagsPlugin,
318+
'docusaurus-plugin-sass',
319+
cond(
320+
tutorialLocales.includes(currentLocale) && [
321+
'@docusaurus/plugin-content-blog',
322+
{
323+
/**
324+
* Required for any multi-instance plugin
325+
*/
326+
id: 'tutorial',
327+
/**
328+
* URL route for the blog section of your site.
329+
* *DO NOT* include a trailing slash.
330+
*/
331+
routeBasePath: 'tutorial',
332+
/**
333+
* Path to data on filesystem relative to site dir.
334+
*/
335+
path: './tutorial',
336+
blogSidebarCount: 0,
337+
showReadingTime: false,
338+
postsPerPage: 'ALL',
339+
},
340+
]
341+
),
342+
].filter(Boolean),
343+
themes: ['@docusaurus/theme-mermaid'],
344+
};
345+
346+
export default config;

src/pages/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { Redirect } from '@docusaurus/router';
2+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
23

34
const HomeRedirect = () => {
4-
return <Redirect to="introduction" />;
5+
const {
6+
siteConfig: { customFields },
7+
} = useDocusaurusContext();
8+
9+
const buildTarget = customFields?.buildTarget;
10+
11+
return <Redirect to={buildTarget === 'tutorial' ? 'tutorial' : 'introduction'} />;
512
};
613

714
export default HomeRedirect;

test-redirects.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// Test all redirects under `/static/_redirects` are reachable
22

3+
if (process.env.BUILD_TARGET === 'tutorial') {
4+
console.log('Skipping test-redirects because BUILD_TARGET is tutorial');
5+
process.exit(0);
6+
}
7+
38
import fs from 'node:fs/promises';
49

510
const content = await fs.readFile('./static/_redirects', 'utf8');

0 commit comments

Comments
 (0)