Skip to content

Commit 7ccbd1e

Browse files
committed
docs: update documentation localization and versioning system
- Migrated `UpdateWritersideVersionTask` to `UpdateDocsVersionTask` - Added `version.json` for dynamic version management in documentation - Improved localization support with Chinese translations - Enhanced UI components with `Translate` usage - Updated Gradle snippets to use dynamic version retrieval - Minor style updates in custom CSS
1 parent bc0d640 commit 7ccbd1e

File tree

16 files changed

+454
-62
lines changed

16 files changed

+454
-62
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ tasks.create("createChangelog") {
5252
}
5353
}
5454

55-
tasks.register<UpdateWritersideVersionTask>("updateWritersideVersion")
55+
tasks.register<UpdateDocsVersionTask>("updateDocsVersion")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import org.gradle.api.DefaultTask
2+
import org.gradle.api.tasks.TaskAction
3+
4+
abstract class UpdateDocsVersionTask : DefaultTask() {
5+
/**
6+
* Update version in docs/src/version.json file with current project version
7+
*/
8+
@TaskAction
9+
fun action() {
10+
val currentVersion = project.version.toString()
11+
12+
// Update version in docs JSON file
13+
val versionJsonFile = project.file("docs/src/version.json")
14+
15+
// Ensure parent directory exists
16+
versionJsonFile.parentFile.mkdirs()
17+
18+
// Directly write the JSON content with current version
19+
val jsonContent = """{"version": "$currentVersion"}"""
20+
versionJsonFile.writeText(jsonContent)
21+
22+
project.logger.info("Updated version to {} in {}", currentVersion, versionJsonFile.path)
23+
}
24+
}

buildSrc/src/main/kotlin/UpdateWritersideVersionTask.kt

Lines changed: 0 additions & 34 deletions
This file was deleted.

docs/docusaurus.config.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import {themes as prismThemes} from 'prism-react-renderer';
22
import type {Config} from '@docusaurus/types';
33
import type * as Preset from '@docusaurus/preset-classic';
4+
import versionInfo from './src/version.json';
45

56
// This runs in Node.js - Don't use client-side code here (browser APIs, JSX...)
7+
/**
8+
* @see https://github.com/facebook/docusaurus/issues/4542#issuecomment-1434839071
9+
*/
10+
function getSiteTagline() {
11+
switch(process.env.DOCUSAURUS_CURRENT_LOCALE) {
12+
case "zh-CN": return '让 suspend 不再害羞';
13+
default: return 'Make suspend no longer shy';
14+
}
15+
}
616

717
const config: Config = {
818
title: 'Kotlin Suspend Transform Compiler Plugin',
9-
tagline: 'Make suspend less shy',
19+
tagline: getSiteTagline(), // 'Make suspend less shy',
1020
favicon: 'img/favicon.ico',
1121

1222
// Future flags, see https://docusaurus.io/docs/api/docusaurus-config#future
@@ -53,32 +63,21 @@ const config: Config = {
5363
sidebarPath: './sidebars.ts',
5464
// Please change this to your repo.
5565
// Remove this to remove the "edit this page" links.
56-
editUrl:
57-
'https://github.com/ForteScarlet/kotlin-suspend-transform-compiler-plugin/tree/dev/docs/',
66+
editUrl: ({locale, docPath}) => {
67+
if (locale === 'zh-CN') {
68+
return `https://github.com/ForteScarlet/kotlin-suspend-transform-compiler-plugin/tree/dev/docs/i18n/zh-CN/docusaurus-plugin-content-docs/current/${docPath}`;
69+
}
70+
return `https://github.com/ForteScarlet/kotlin-suspend-transform-compiler-plugin/tree/dev/docs/${docPath}`;
71+
},
5872
showLastUpdateTime: true,
5973
lastVersion: 'current',
6074
versions: {
6175
current: {
6276
badge: true,
63-
label: 'Latest',
77+
label: 'v' + versionInfo.version,
6478
},
6579
}
6680
},
67-
// blog: {
68-
// showReadingTime: true,
69-
// feedOptions: {
70-
// type: ['rss', 'atom'],
71-
// xslt: true,
72-
// },
73-
// // Please change this to your repo.
74-
// // Remove this to remove the "edit this page" links.
75-
// editUrl:
76-
// 'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
77-
// // Useful options to enforce blogging best practices
78-
// onInlineTags: 'warn',
79-
// onInlineAuthors: 'warn',
80-
// onUntruncatedBlogPosts: 'warn',
81-
// },
8281
theme: {
8382
customCss: './src/css/custom.css',
8483
},
@@ -88,7 +87,7 @@ const config: Config = {
8887

8988
themeConfig: {
9089
// Replace with your project's social card
91-
image: 'img/docusaurus-social-card.jpg',
90+
// image: 'img/docusaurus-social-card.jpg',
9291
navbar: {
9392
title: 'Kotlin Suspend Transform Compiler Plugin',
9493
// logo: {
@@ -102,10 +101,15 @@ const config: Config = {
102101
position: 'left',
103102
label: 'Documentation',
104103
},
104+
{
105+
type: 'docsVersionDropdown',
106+
position: 'right',
107+
versions: ['current'],
108+
},
105109
{
106110
href: 'https://github.com/ForteScarlet/kotlin-suspend-transform-compiler-plugin',
107-
label: 'GitHub',
108111
position: 'right',
112+
className: 'header-github-link',
109113
'aria-label': 'GitHub repository',
110114
},
111115
{

0 commit comments

Comments
 (0)