Skip to content

Commit eccabb7

Browse files
authored
Merge pull request #629 from processing/fix/hydrated-components
Use import.meta.env + ENV file so hydrated components work
2 parents 3ac5e0f + 28e8cda commit eccabb7

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

src/components/GridItem/Reference.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const { item } = Astro.props;
2020
</p>
2121
<p class="text-sm mt-xxs">
2222
{
23-
`${item.data.description.replace(/<[^>]*>/g, "").split(/(\.|。)(\s|$)/, 1)[0]}.`
23+
`${item.data.description?.replace(/<[^>]*>/g, "").split(/(\.|。)(\s|$)/, 1)[0]}.`
2424
}
2525
</p>
2626
</a>

src/content/reference/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const categories = [
2525

2626
const paramSchema = z.object({
2727
name: z.string(),
28-
description: z.string(),
28+
description: z.string().optional(),
2929
type: z.string().optional(),
3030
optional: z.coerce.boolean().optional(),
3131
});
@@ -60,10 +60,10 @@ export const referenceSchema = z.object({
6060
// Name of the reference item
6161
title: z.string(),
6262
// Module this item is within (for example: Color)
63-
module: z.string(),
63+
module: z.string().optional().default('Shape'),
6464
submodule: z.string().optional(),
6565
file: z.string(),
66-
description: z.string(),
66+
description: z.string().optional(),
6767
line: z.number().or(z.string().transform((v) => parseInt(v, 10))),
6868
params: z.array(paramSchema).optional(),
6969
overloads: z.array(z.object({ params: z.array(paramSchema) })).optional(),

src/globals/globals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const sketchesPerPage = 12 as const;
1414
export const eventsPerPage = 12 as const;
1515

1616
export const cdnLibraryUrl =
17-
process.env.P5_LIBRARY_PATH ||
18-
`https://cdn.jsdelivr.net/npm/p5@${p5Version}/lib/p5.min.js` as const;
17+
import.meta.env.PUBLIC_P5_LIBRARY_PATH ||
18+
(`https://cdn.jsdelivr.net/npm/p5@${p5Version}/lib/p5.min.js` as const);
1919
export const fullDownloadUrl =
2020
`https://github.com/processing/p5.js/releases/download/v${p5Version}/p5.zip` as const;
2121
export const libraryDownloadUrl =

src/scripts/branchTest.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { execSync } from "child_process";
2-
import { existsSync, rmSync } from "fs";
2+
import { existsSync, readFileSync, rmSync, writeFileSync } from "fs";
33
import path from "path";
44
import { fileURLToPath } from "url";
55

@@ -17,7 +17,16 @@ if (!match) {
1717
const repoUrl = match[1];
1818
const branch = match[2];
1919

20-
const env = `P5_LIBRARY_PATH='/p5.min.js' P5_REPO_URL='${repoUrl}' P5_BRANCH='${branch}'`;
20+
const envVars = [`PUBLIC_P5_LIBRARY_PATH='/p5.min.js'`, `P5_REPO_URL='${repoUrl}'`, `P5_BRANCH='${branch}'`];
21+
const env = envVars.join(' ');
22+
23+
const envFilePath = path.join(__dirname, '../../.env');
24+
let currentEnv = existsSync(envFilePath) ? readFileSync(envFilePath).toString() : '';
25+
currentEnv = currentEnv
26+
.split('\n')
27+
.filter((line: string) => !line.startsWith('P5_') && !line.startsWith('PUBLIC_P5_'))
28+
.join('\n')
29+
writeFileSync(envFilePath, currentEnv + '\n' + envVars.join('\n'));
2130

2231
// First delete the existing cloned p5 to make sure we clone fresh
2332
const parsedP5Path = path.join(__dirname, "./parsers/in/p5.js/");

src/scripts/resetBranchTest.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
import { fileURLToPath } from "url";
22
import path from "path";
3-
import { existsSync, rmSync } from "fs";
3+
import { existsSync, readFileSync, rmSync, writeFileSync } from "fs";
44
import simpleGit from "simple-git";
55

66
async function main() {
77
const __dirname = path.dirname(fileURLToPath(import.meta.url));
88

9-
const referencePath = path.join(__dirname, '../content/reference/');
9+
const referencePath = path.join(__dirname, '../content/reference/en/');
1010
const dataPath = path.join(__dirname, '../../public/reference/data.json')
1111
rmSync(referencePath, { recursive: true });
1212

13+
const envFilePath = path.join(__dirname, '../../.env');
14+
if (existsSync(envFilePath)) {
15+
const currentEnv = readFileSync(envFilePath).toString();
16+
writeFileSync(
17+
envFilePath,
18+
currentEnv
19+
.split('\n')
20+
.filter((line: string) => !line.startsWith('P5_') && !line.startsWith('PUBLIC_P5_'))
21+
.join('\n')
22+
);
23+
}
24+
1325
const git = simpleGit();
1426
await git.checkout('HEAD', [referencePath, dataPath]);
1527

0 commit comments

Comments
 (0)