Skip to content

Commit a5681f5

Browse files
Avoid collection race condition
1 parent 8749372 commit a5681f5

2 files changed

Lines changed: 24 additions & 31 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ jobs:
2323
uses: actions/checkout@v6
2424
- name: Install, build, and upload your site
2525
uses: withastro/action@v6
26-
with:
27-
cache: false
2826
deploy:
2927
needs: build
3028
runs-on: ubuntu-latest

src/content.config.ts

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
import {defineCollection, getCollection} from 'astro:content';
1+
import {defineCollection} from 'astro:content';
22
import {glob, type Loader} from 'astro/loaders';
33
import { docsLoader } from '@astrojs/starlight/loaders';
44
import { docsSchema } from '@astrojs/starlight/schema';
55
import { autoSidebarLoader } from 'starlight-auto-sidebar/loader'
66
import { autoSidebarSchema } from 'starlight-auto-sidebar/schema'
77

8+
const skriptReleases = await fetch('https://api.github.com/repos/SkriptLang/Skript/releases?per_page=100', {
9+
headers: {
10+
'Accept': 'application/vnd.github+json',
11+
'X-GitHub-Api-Version': '2022-11-28',
12+
'User-Agent': 'SkriptLang',
13+
},
14+
}).then(response => {
15+
if (!response.ok) {
16+
throw new Error("Failed to fetch versions... aborting");
17+
}
18+
return response.json();
19+
});
20+
821
export const collections = {
922
docs: defineCollection({
1023
loader: docsLoader(),
@@ -27,26 +40,14 @@ export const collections = {
2740
}),
2841
}),
2942
skriptReleasesJson: defineCollection({
30-
loader: async() =>
31-
fetch('https://api.github.com/repos/SkriptLang/Skript/releases?per_page=100', {
32-
headers: {
33-
'Accept': 'application/vnd.github+json',
34-
'X-GitHub-Api-Version': '2022-11-28',
35-
'User-Agent': 'SkriptLang',
36-
},
37-
}).then(response => {
38-
if (!response.ok) {
39-
throw new Error("Failed to fetch versions... aborting");
40-
}
41-
return response.json();
42-
}).then(json => {
43-
let order = 0;
44-
return json.map((release: any) => ({
45-
...release,
46-
id: release.id.toString(),
47-
order: order++,
48-
}));
49-
})
43+
loader: () => {
44+
let order = 0;
45+
return skriptReleases.map((release: any) => ({
46+
...release,
47+
id: release.id.toString(),
48+
order: order++,
49+
}));
50+
}
5051
}),
5152
githubReleaseBodies: defineCollection({
5253
loader: function releaseLoader() {
@@ -55,15 +56,9 @@ export const collections = {
5556
async load({ renderMarkdown, store }) {
5657
store.clear();
5758

58-
const skriptReleases = (await getCollection("skriptReleasesJson"));
5959
const entries = {
60-
'Skript/latest': skriptReleases
61-
.find(entry => entry.data.order == 0)!
62-
.data,
63-
'Skript/latestStable': skriptReleases
64-
.sort((a, b) => a.data.order - b.data.order)!
65-
.find(entry => !entry.data.prerelease)!
66-
.data,
60+
'Skript/latest': skriptReleases[0],
61+
'Skript/latestStable': skriptReleases.find((entry: any) => !entry.prerelease)!,
6762
}
6863

6964
for (const [id, data] of Object.entries(entries)) {

0 commit comments

Comments
 (0)