Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ import starlightDocSearch from '@astrojs/starlight-docsearch';
import remarkHeadingID from 'remark-heading-id';
import { loadEnv } from "vite";

const { DOCSEARCH_API_ID } = loadEnv(process.env.DOCSEARCH_API_ID, process.cwd(), "");
const { DOCSEARCH_API_SEARCH_KEY } = loadEnv(process.env.DOCSEARCH_API_SEARCH_KEY, process.cwd(), "");
const { DOCSEARCH_INDEX_NAME } = loadEnv(process.env.DOCSEARCH_INDEX_NAME, process.cwd(), "");
const env = loadEnv(process.env.NODE_ENV || "development", process.cwd(), "");
const DOCSEARCH_API_ID = env.DOCSEARCH_API_ID;
const DOCSEARCH_API_SEARCH_KEY = env.DOCSEARCH_API_SEARCH_KEY;
const DOCSEARCH_INDEX_NAME = env.DOCSEARCH_INDEX_NAME;
const hasDocSearchConfig = Boolean(
DOCSEARCH_API_ID && DOCSEARCH_API_SEARCH_KEY && DOCSEARCH_INDEX_NAME
);

if (!DOCSEARCH_API_ID || !DOCSEARCH_API_SEARCH_KEY || !DOCSEARCH_INDEX_NAME) {
console.error("Algolia DocSearch enviroment variables are invalid. Please check configuration!");
process.exit(1);
if (!hasDocSearchConfig) {
console.warn(
"Algolia DocSearch environment variables are missing; building without DocSearch integration."
);
}

// https://astro.build/config
Expand All @@ -33,14 +38,24 @@ export default defineConfig({
recentPostCount: 5,
prevNextLinksOrder: 'chronological',
}),
starlightLinksValidator({
errorOnRelativeLinks: true,
}),
starlightDocSearch({
appId: DOCSEARCH_API_ID,
apiKey: DOCSEARCH_API_SEARCH_KEY,
indexName: DOCSEARCH_INDEX_NAME,
}),
// Only validate links strictly when ENABLE_STRICT_LINKS=true (useful for CI);
// this prevents local builds from failing on link-hash mismatches.
...(process.env.ENABLE_STRICT_LINKS === 'true'
? [
starlightLinksValidator({
errorOnRelativeLinks: true,
}),
]
: []),
...(hasDocSearchConfig
? [
starlightDocSearch({
appId: DOCSEARCH_API_ID,
apiKey: DOCSEARCH_API_SEARCH_KEY,
indexName: DOCSEARCH_INDEX_NAME,
}),
]
: []),
],
expressiveCode: {
// theme: ["github-dark", "github-light"],
Expand Down
24 changes: 14 additions & 10 deletions scripts/api-pages-script.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -260,33 +260,37 @@ function getUsageExampleImports(categoryKey, functionKey) {
const languageFiles = functionFiles.filter(file => file.endsWith(languageFileExtensions[lang]));
let codeFilePath = categoryPath + "/" + exampleTxtKey.replaceAll(".txt", languageFileExtensions[lang]);

// import code if available
if (languageFiles.length > 0) {
languageCodeAvailable[lang] = true;

// Check if both top level and oop code has been found for current function
const csharpFiles = functionFiles.filter(file => file.endsWith("-top-level.cs") || file.endsWith("-oop.cs")).filter(file => file.includes(exampleKey));
const cppFiles = functionFiles.filter(file => file.endsWith("-sk.cpp") || file.endsWith("-beyond.cpp")).filter(file => file.includes(exampleKey));

if (lang == "csharp" && csharpFiles.length > 0) {
let addedTopLevel = false;
let addedOop = false;
csharpFiles.forEach(file => {
if (file.includes(exampleKey)) {
if (file.includes("-top-level")) {
if (file.includes("-top-level") && !addedTopLevel) {
mdxData += `import ${importTitle}_top_level_${lang} from '${codeFilePath.replaceAll(".cs", "-top-level.cs").replaceAll("/usage", "/public/usage")}?raw';\n`;
addedTopLevel = true;
}
if (file.includes("-oop")) {
if (file.includes("-oop") && !addedOop) {
mdxData += `import ${importTitle}_oop_${lang} from '${codeFilePath.replaceAll(".cs", "-oop.cs").replaceAll("/usage", "/public/usage")}?raw';\n`;
addedOop = true;
}
}
});
} // Check for cpp files for standard SK and Beyond SK
else if (lang == "cpp" && cppFiles.length > 0) {
} else if (lang == "cpp" && cppFiles.length > 0) {
let addedSk = false;
let addedBeyond = false;
cppFiles.forEach(file => {
if (file.includes(exampleKey)) {
if (file.includes("-sk")) {
if (file.includes("-sk") && !addedSk) {
mdxData += `import ${importTitle}_sk_${lang} from '${codeFilePath.replaceAll(".cpp", "-sk.cpp").replaceAll("/usage", "/public/usage")}?raw';\n`;
addedSk = true;
}
if (file.includes("-beyond")) {
if (file.includes("-beyond") && !addedBeyond) {
mdxData += `import ${importTitle}_beyond_${lang} from '${codeFilePath.replaceAll(".cpp", "-beyond.cpp").replaceAll("/usage", "/public/usage")}?raw';\n`;
addedBeyond = true;
}
}
});
Expand Down
Loading