-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnuxt.config.ts
More file actions
342 lines (325 loc) · 9.61 KB
/
Copy pathnuxt.config.ts
File metadata and controls
342 lines (325 loc) · 9.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
// https://nuxt.com/docs/api/configuration/nuxt-config
import ViteYaml from "@modyfi/vite-plugin-yaml";
import tailwindcss from "@tailwindcss/vite";
import svgLoader from "vite-svg-loader";
import fs from "fs";
import { join, resolve, basename, dirname, parse } from "node:path";
import glob from "fast-glob";
import { readFileSync } from "fs";
import matter from "gray-matter";
const BASE = process.env.NUXT_APP_BASE_URL || "/";
const ISPREVIEW = process.env.NUXT_SITE_ENV === "preview";
export default defineNuxtConfig({
compatibilityDate: "2024-04-03",
devtools: { enabled: false },
pages: true,
css: ["@/assets/css/tailwind.css"],
app: {
pageTransition: { name: "page", mode: "out-in" },
head: {
link: [
{
rel: "icon",
href: `${BASE}favicon.svg`,
media: "(prefers-color-scheme: light)",
},
{
rel: "icon",
href: `${BASE}favicon.png`,
media: "(prefers-color-scheme: light)",
},
{
rel: "icon",
href: `${BASE}logo-dark.svg`,
media: "(prefers-color-scheme: dark)",
},
{
rel: "icon",
href: `${BASE}logo-dark.png`,
media: "(prefers-color-scheme: dark)",
},
],
},
},
runtimeConfig: {
public: {
NUXT_SITE_ENV: process.env.NUXT_SITE_ENV || "production",
posthogPublicKey: "phc_hoxK6NUuVi0AWHTEMWYszchraAZ0BcAQgjq15fC6LeH",
posthogHost: "https://eu.i.posthog.com",
},
},
postcss: {
plugins: {
"@tailwindcss/postcss": true,
},
},
site: {
indexable: process.env.NUXT_SITE_ENV === "production",
url: "https://osai-index.eu",
name: "European Open Source AI Index",
defaultOgImage: "/osai-index-logo.png",
trailingSlash: false,
},
modules: [
[
"./modules/github.module",
{
repositories: [
{
name: "data",
owner: "Language-Technology-Assessment",
repo: "main-database",
},
{
name: "website",
owner: "Language-Technology-Assessment",
repo: "European-open-AI-index",
},
],
},
],
"@nuxtjs/seo",
"@nuxt/content",
"@nuxt/icon",
"@nuxt/image",
"@nuxtjs/critters", // "@nuxtjs/i18n",
"@pinia/nuxt",
"@nuxtjs/mdc",
],
image: {
// dir: resolve(__dirname, "repos/website/"),
dir: "repos/website",
},
linkChecker: {
skipInspections: ["link-text"],
},
robots: {
robotsTxt: BASE === "/" ? true : false,
},
sitemap: {
urls: async () => {
const urls: Array<string> = [];
const pages = await glob("./repos/website/pages/**/*.md");
pages.map((x) => {
let dir = basename(dirname(x));
let p = parse(x);
let fromroot = x.split("pages")[1];
if (dir !== "guides" && dir !== "news" && fromroot) {
if (p.name === "index") {
urls.push(parse(fromroot).dir);
} else {
urls.push(fromroot.replace(/\.md$/, ""));
}
}
});
// Helper function to parse frontmatter and check status
const parseFileAndCheckStatus = (filePath: string) => {
try {
const content = readFileSync(filePath, "utf-8");
const { data } = matter(content);
return data.status === "published";
} catch (error) {
console.warn(`Error parsing ${filePath}:`, error);
return false;
}
};
// news+guides - only include published articles
const newsPages = await glob("./repos/website/pages/news/**/*.md");
const guidePages = await glob("./repos/website/pages/guides/**/*.md");
// Add news routes (only published)
for (const file of newsPages) {
const isPublished = parseFileAndCheckStatus(file);
if (isPublished) {
const filename = parse(file).name;
urls.push(`/news/${filename}`);
}
}
// Add guides routes (only published)
for (const file of guidePages) {
const isPublished = parseFileAndCheckStatus(file);
if (isPublished) {
const filename = parse(file).name;
urls.push(`/guides/${filename}`);
}
}
// models
const models = await glob("./repos/data/*.yaml");
models.map((file) => {
let name = basename(file);
if (
!name.match(
/(a_submission_template\.yaml|^_parameters|^readme\.md|^\.)/,
)
) {
const filename = name.replace(".yaml", "");
// extendPages
urls.push(`/model/${filename.toLowerCase()}`);
}
});
return urls;
},
},
hooks: {
async "nitro:config"(nitroConfig) {
const models = await glob("./repos/data/*.yaml");
models.map((file) => {
let name = basename(file);
if (
!name.match(
/(a_submission_template\.yaml|^_parameters|^readme\.md|^\.)/,
)
) {
const filename = name.replace(".yaml", "");
// extendPages
nitroConfig.prerender?.routes?.push(
`/model/${filename.toLowerCase()}`,
);
}
});
const newsPages = await glob("./repos/website/pages/news/**/*.md");
const guidePages = await glob("./repos/website/pages/guides/**/*.md");
// Add news routes
newsPages.map((file) => {
const filename = parse(file).name;
nitroConfig.prerender?.routes?.push(`/news/${filename}`);
});
// Add guides routes
guidePages.map((file) => {
const filename = parse(file).name;
nitroConfig.prerender?.routes?.push(`/guides/${filename}`);
});
},
"nitro:build:public-assets": async (nitro) => {
const publicDir = nitro.options.output.publicDir;
fs.writeFileSync(
join(publicDir, "CNAME"),
process.env.NUXT_SITE_ENV === "preview"
? "preview.osai-index.eu"
: "osai-index.eu",
);
},
"build:before": async function () {
const results: Record<
string,
Array<{
slug: string;
title?: string;
date?: string;
author?: string;
}>
> = {};
const models = await glob("./repos/data/*.yaml");
// Function to find models mentioned in guide files
const findModelsInGuides = async (modelName: string) => {
const guideFiles = await glob("./repos/website/pages/guides/**/*.md");
const mentioningGuides = [];
for (const guideFile of guideFiles) {
try {
const content = readFileSync(guideFile, "utf-8");
const lines = content.split("\n");
// Look for lines starting with "models:" and check if model is mentioned
for (let i = 0; i < lines.length; i++) {
const currentLine = lines[i];
if (typeof currentLine !== "string") continue;
const line = currentLine.trim();
if (line.startsWith("models:")) {
// Check this line and subsequent lines for the model name
let j = i;
while (j < lines.length) {
const currentLineAtJ = lines[j];
if (!currentLineAtJ) break;
if (
j !== i &&
!currentLineAtJ.startsWith(" ") &&
!currentLineAtJ.startsWith("-")
) {
break;
}
const asYaml = matter(content).data;
if (
currentLineAtJ
.toLowerCase()
.includes(modelName.toLowerCase()) &&
asYaml?.status === "published"
) {
mentioningGuides.push({
slug: parse(guideFile).name,
title: asYaml.title,
date: asYaml.date,
author: asYaml.author,
});
break;
}
j++;
}
}
}
} catch (error) {
console.warn(`Error reading guide file ${guideFile}:`, error);
}
}
return mentioningGuides;
};
for (let i in models) {
const model = models[i];
if (!model) continue;
const filename = parse(model).name;
// Find which guides mention this model
const mentioningGuides = await findModelsInGuides(filename);
if (mentioningGuides.length > 0) {
results[filename] = mentioningGuides;
}
}
try {
fs.mkdirSync("./repos");
} catch (err) {
console.warn("fine");
}
// Log the complete results
fs.writeFileSync(
"./repos/models-in-guides.json",
JSON.stringify(results, null, 2),
);
const modelcount = models.length;
fs.writeFileSync(
"./repos/modelcount.json",
JSON.stringify({ modelcount }, null, 2),
);
},
},
mdc: {
components: {
map: {
a: "a",
},
},
},
routeRules: {
"/the-index": {
redirect: { to: "/database", statusCode: 301 },
},
},
vite: {
css: {},
plugins: [
ViteYaml(),
tailwindcss(),
svgLoader({
svgoConfig: {
multipass: true,
plugins: [
{
name: "preset-default",
params: {
overrides: {
// @see https://github.com/svg/svgo/issues/1128
removeViewBox: false,
},
},
},
],
},
}),
],
},
});