Skip to content

Commit 9212d15

Browse files
Script improvements, favicon (#36)
1 parent 891a9ee commit 9212d15

File tree

8 files changed

+45
-35
lines changed

8 files changed

+45
-35
lines changed

astro.config.mjs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import starlightLinksValidator from 'starlight-links-validator'
55

66

77
// !! UPDATE LATEST VERSION HERE !!
8-
// format semver with underscores to make it look like a semver would in a URL
9-
var latest_display_name = 'Version 2.0';
10-
var latest_dir_name = '2_0';
8+
let latest_version = '2.0';
9+
10+
let latest_dir_name = latest_version.replace('.', '-');
1111

1212
// https://astro.build/config
1313
export default defineConfig({
@@ -16,6 +16,24 @@ export default defineConfig({
1616
integrations: [
1717
starlight({
1818
title: 'ICU4X',
19+
head: [
20+
{
21+
tag: 'link',
22+
attrs: {
23+
rel: "icon",
24+
href: "/icon_black.png",
25+
media: "(prefers-color-scheme: light)",
26+
}
27+
},
28+
{
29+
tag: 'link',
30+
attrs: {
31+
rel: "icon",
32+
href: "/icon_white.png",
33+
media: "(prefers-color-scheme: dark)",
34+
}
35+
},
36+
],
1937
social: {
2038
github: 'https://github.com/unicode-org/icu4x',
2139
},
@@ -50,7 +68,7 @@ export default defineConfig({
5068
],
5169
},
5270
{
53-
label: latest_display_name,
71+
label: 'Version 2.0',
5472
badge: {
5573
text: 'New',
5674
variant: 'success',
@@ -71,7 +89,7 @@ export default defineConfig({
7189
items: [
7290
{
7391
label: 'Rust',
74-
link: 'https://docs.rs/icu/2.0.0',
92+
link: 'https://docs.rs/icu/2.0',
7593
badge: { text: '↗', variant: 'tip' },
7694
attrs: { target: '_blank' },
7795

public/icon_black.png

1.04 KB
Loading

public/icon_white.png

1.86 KB
Loading
-1.09 MB
Binary file not shown.

src/content/docs/2_0/tutorials/data-management.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ This will generate a `my_data_blob.postcard` file containing the serialized data
160160

161161
Unlike `BakedDataProvider`, `BlobDataProvider` (and `FsDataProvider`) does not perform locale fallbacking. For example, if `en-US` is requested but only `en` data is available, then the data request will fail. To enable fallback, we can wrap the provider in a `LocaleFallbackProvider`.
162162

163-
Note that fallback comes at a cost, as fallbacking code and data has to be included and executed on every request. If you don't need fallback (disclaimer: you probably do), you can use the `BlobDataProvider` directly (for baked data, see [`Options::skip_internal_fallback`](https://docs.rs/icu_provider_baked/2.0.0/icu_provider_baked/export/struct.Options.html)).
163+
Note that fallback comes at a cost, as fallbacking code and data has to be included and executed on every request. If you don't need fallback (disclaimer: you probably do), you can use the `BlobDataProvider` directly (for baked data, see [`Options::skip_internal_fallback`](https://docs.rs/icu_provider_baked/2.0/icu_provider_baked/export/struct.Options.html)).
164164

165165
We can then use the provider in our code:
166166

@@ -268,4 +268,4 @@ We have learned how to generate data and load it into our programs, optimize dat
268268

269269
For a deeper dive into configuring your data providers in code, see [data-provider-runtime.md].
270270

271-
You can learn more about datagen, including the Rust API which we have not used in this tutorial, by reading [the docs](https://docs.rs/icu_provider_export/2.0.0/).
271+
You can learn more about datagen, including the Rust API which we have not used in this tutorial, by reading [the docs](https://docs.rs/icu_provider_export/2.0/).

src/content/docs/2_0/tutorials/date-picker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Now we would also like to format the current time.
218218

219219
### Rust Part 4
220220

221-
Use the API documentation for [`icu::time::DateTime`](https://docs.rs/icu/2.0.0/icu/time/struct.DateTime.html) and [`icu::datetime::fieldsets`](https://docs.rs/icu/2.0.0/icu/datetime/fieldsets/index.html) to expand your app to format both date and time.
221+
Use the API documentation for [`icu::time::DateTime`](https://docs.rs/icu/2.0/icu/time/struct.DateTime.html) and [`icu::datetime::fieldsets`](https://docs.rs/icu/2.0/icu/datetime/fieldsets/index.html) to expand your app to format both date and time.
222222

223223
### JavaScript Part 4
224224

src/content/docs/2_0/tutorials/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ This concludes this introduction tutorial. With the help of `Locale` and `DateTi
165165

166166
Internationalization is a broad domain and there are many more components in `ICU4X`.
167167

168-
Next, learn how to [generate optimized data for your binary](/2_0/tutorials/data-management), [configure your Cargo.toml file](https://github.com/unicode-org/icu4x/tree/release%2F2.0/tutorials/../examples/cargo), or continue exploring by reading [the docs](https://docs.rs/icu/2.0.0/).
168+
Next, learn how to [generate optimized data for your binary](/2_0/tutorials/data-management), [configure your Cargo.toml file](https://github.com/unicode-org/icu4x/tree/release%2F2.0/tutorials/../examples/cargo), or continue exploring by reading [the docs](https://docs.rs/icu/2.0/).
169169

170170

171171

tools/github-to-astro.ts

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ function icu4xGfmToAstroMd(content: string, inFilePath: string, ctx: Context) {
138138

139139
const order = TUTORIAL_ORDER.get(inFilePath.split('/')[inFilePath.split('/').length - 1]);
140140

141-
console.log(inFilePath);
142-
143141
const frontMatter = icu4xAstroMdFrontMatter(foundTitle, order);
144142

145143
let replacementContent = transformMdBody(content, ctx);
@@ -202,9 +200,9 @@ function printHelp() {
202200
console.log("Convert ICU4X Github repo Markdown tutorials to Astro MDX files");
203201
console.log();
204202
console.log("Usage:");
205-
console.log("\tnpm run icu4x-convert -- --inDir=<input-dir> --outDir=<output-dir> --icu4xRef=<ICU4X-git-ref> --webDirName=<version-based-dir-name> --sitePrefix=<site-prefix-str-else-emptystr> --astroVersion=<semver>");
203+
console.log("\tnpm run icu4x-convert -- --icu4xDir=<input-dir> --icu4xVersion=<minor version> [--icu4xRef=<ICU4X-git-ref>] [--sitePrefix=<site-prefix-str-else-emptystr>] --astroVersion=<semver>");
206204
console.log();
207-
console.log("Example: npm run icu4x-convert -- --inDir=/path/to/icu4x/tutorials/ --outDir=/path/to/icu4x-docs/src/content/docs/ --icu4xVersion=1.5.0 --icu4xRef=release/1.5 --webDirName=1_5 [--sitePrefix=/uriPrefix] --astroVersion=4.16.18")
205+
console.log("Example: npm run icu4x-convert -- --icu4xDir=../path/to/icu4x/ --icu4xVersion=2.1 [--icu4xRef=release/2.1-draft] [--sitePrefix=/uriPrefix] --astroVersion=4.16.18")
208206
}
209207

210208
/**
@@ -214,23 +212,16 @@ function printHelp() {
214212
function parseCLIArgs() {
215213
let parsedArgs = parseArgs({
216214
options: {
217-
inDir: {
215+
icu4xDir: {
218216
type: "string",
219217
short: "i",
220218
},
221-
outDir: {
222-
type: "string",
223-
short: "o",
224-
},
225219
icu4xVersion: {
226220
type: "string",
227221
},
228222
icu4xRef: {
229223
type: "string",
230224
},
231-
webDirName: {
232-
type: "string",
233-
},
234225
// site prefix, as used by static site generator tools.
235226
// if this were hosted on Github pages,
236227
sitePrefix: {
@@ -246,17 +237,20 @@ function parseCLIArgs() {
246237
let returnVal = {
247238
positionals: positionals,
248239
values: {
249-
inDir: values["inDir"] ?? (() => {throw new Error("Need inDir")})(),
250-
outDir: values["outDir"] ?? (() => {throw new Error("Need outDir")})(),
240+
icu4xDir: values["icu4xDir"] ?? (() => {throw new Error("Need icu4xDir")})(),
251241
icu4xVersion: values["icu4xVersion"] ?? (() => {throw new Error("Need icu4xVersion")})(),
252-
icu4xRef: values["icu4xRef"] ?? (() => {throw new Error("Need icu4xRef")})(),
253-
webDirName: values["webDirName"] ?? (() => {throw new Error("Need webDirName")})(),
242+
icu4xRef: values["icu4xRef"] ?? `release/${values["icu4xVersion"]}`,
254243
sitePrefix: values["sitePrefix"] ?? "", // default value for sitePrefix is "" because
255244
// URIs for base site icu4x.unicode.org do not need
256245
// a prefix, unlike hosting on Github Pages
257246
astroVersion: values["astroVersion"] ?? (() => {throw new Error("Need astroVersion")})(),
258247
}
259248
};
249+
250+
if ((values.icu4xVersion.match(/\./g) || []).length > 1) {
251+
console.log("use only a minor version, e.g. 2.1")
252+
process.exit(1);
253+
}
260254
return returnVal;
261255
} catch (err) {
262256
console.error('Missing CLI options.', err);
@@ -265,31 +259,29 @@ function parseCLIArgs() {
265259
}
266260
}
267261

268-
function genConfigEntry(icu4xRef, webDirName, icu4xVersion) {
269-
270-
}
271-
272262
// "main"
273263

274264
try {
265+
process.chdir(path.join(import.meta.dirname, '..'));
266+
275267
const parsedArgs = parseCLIArgs();
276268
console.log("argv", process.argv);
277269
let {values, positionals} = parsedArgs;
278270

279-
const inputDirPath: string = values["inDir"];
271+
const icu4xDir: string = values["icu4xDir"];
280272
const icu4xVersion = values["icu4xVersion"];
281273
const icu4xRef = values["icu4xRef"];
282274
const sitePrefix = values["sitePrefix"];
283-
const webDirName = values["webDirName"];
284-
const outputDirPath = path.join(values["outDir"], webDirName);
275+
const webDirName = icu4xVersion.replace('.', '_');
276+
const outputDirPath = path.join('src/content/docs', webDirName);
285277

286278
const context = new Context({icu4xVersion, icu4xRef, webDirName, sitePrefix});
287279

288-
await convertDirFiles(inputDirPath, outputDirPath, context);
280+
await convertDirFiles(path.join(icu4xDir, 'tutorials'), outputDirPath, context);
289281

290282
console.log(
291283
`{
292-
label: latest_display_name,
284+
label: 'Version ${icu4xVersion}',
293285
badge: {
294286
text: 'New',
295287
variant: 'success',
@@ -347,7 +339,7 @@ try {
347339

348340

349341
console.log("Markdown conversion finished successfully");
350-
console.log("Task: Add the above JSON to astro.config.mjs if it doesn't exist yet, set the previous version to collapsed: true");
342+
console.log("Task: Add the above JSON to astro.config.mjs if it doesn't exist yet");
351343
console.log(`Task: Make sure to dump artifacts in public/${webDirName}`);
352344

353345
} catch (error: unknown) {

0 commit comments

Comments
 (0)