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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
82 changes: 23 additions & 59 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,93 +3,57 @@ import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
import fs from 'node:fs';
import { fetchDefinitions, OUTPUT_PATH } from './scripts/fetch-definitions.js';
import { sidebar } from './astro.sidebar.js';


// Ensure LSL definitions are available
if (!fs.existsSync(OUTPUT_PATH)) {
console.log('LSL definitions not found, fetching from GitHub...');
await fetchDefinitions();
}


// Load textmate grammar for LSL
const lslLang = JSON.parse(
fs.readFileSync(new URL('./src/definitions/lsl.tmLanguage.json', import.meta.url), 'utf-8')
)


// https://astro.build/config
export default defineConfig({
site: 'https://create.secondlife.com',
redirects: {
'/': '/script/',
},
integrations: [
starlight({
title: 'Second Life Creation',
title: 'Second Life Create',
favicon: '/favicon.svg',
editLink: {
baseUrl: 'https://github.com/secondlife/create/edit/main/',
defaultLocale: 'root',
locales: {
root: { label: 'English', lang: 'en' },
},
social: [
{ icon: 'discord', label: 'Discord', href: 'https://discord.gg/secondlifeofficial' },
{
icon: 'github',
label: 'GitHub',
href: 'https://github.com/secondlife/create',
},
{ icon: 'github', label: 'GitHub', href: 'https://github.com/secondlife/create' },
],
logo: {
src: './src/assets/sl-logo.svg',
},
expressiveCode: {
shiki: {
langs: [lslLang],
},
logo: { src: './src/assets/sl-logo.svg' },

tableOfContents: false,
sidebar,
components: {
Sidebar: './src/components/starlight/Sidebar.astro',
},
customCss: [
'./src/styles/custom.css',
],
defaultLocale: 'root',
locales: {
root: {
label: 'English',
lang: 'en',
},
editLink: {
baseUrl: 'https://github.com/secondlife/create/edit/main/',
},
sidebar: [
{
label: 'Script',
items: [
{ label: 'Getting Started', slug: 'script' },
// {
// label: 'Guides',
// autogenerate: { directory: 'script/guides' },
// },
// {
// label: 'Recipes',
// autogenerate: { directory: 'script/recipes' },
// },
{
label: 'Learn SLua',
collapsed: true,
autogenerate: { directory: 'script/learn-slua' },
},
{
label: 'Reference',
items: [
{
label: 'LSL',
collapsed: true,
autogenerate: { directory: 'script/lsl-reference' },
},
{
label: 'SLua',
collapsed: true,
autogenerate: { directory: 'script/slua-reference' },
},
],
},
],

routeMiddleware: './config/middleware.js',
expressiveCode: {
shiki: {
langs: [lslLang],
},
],
},
}),
],
});
102 changes: 102 additions & 0 deletions astro.sidebar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { portal, tab, group } from './config/sidebar.js';

export const sidebar = [
// Scripting Portal
portal('script', {
items: [
tab('script.introduction', {
autogenerate: { directory: 'script/getting-started' },
}),

tab('script.guidebook', {
items: [
group('script.guidebook.features', { autogenerate: { directory: 'script/features' }}),
group('script.guidebook.guides', { slug: 'script/guides' }),
group('script.guidebook.recipes', { slug: 'script/recipes' }),
]
}),

tab('script.language', {
collapsed: false,
items: [
group('script.language.slua', {
autogenerate: { directory: 'script/slua' },
}),
group('script.language.lsl', {
collapsed: true,
autogenerate: { directory: 'script/lsl' },
}),
]
}),

tab('script.reference', {
collapsed: false,
items: [
group('script.reference.categories', { slug: 'script/reference/categories' }),
group('script.reference.events', { slug: 'script/reference/events' }),
group('script.reference.constants', { slug: 'script/reference/constants' }),
group('script.reference.stdlib', {
collapsed: false,
autogenerate: { directory: 'script/reference/standard-library' },
}),
group('script.reference.luau', {
collapsed: false,
autogenerate: { directory: 'script/reference/luau' },
}),
group('script.reference.lsl', {
collapsed: false,
items: [
group('script.reference.lsl.functions', {
collapsed: true,
autogenerate: { directory: 'script/reference/lsl/functions' },
}),
group('script.reference.lsl.events', {
collapsed: true,
autogenerate: { directory: 'script/reference/lsl/events' },
}),
group('script.reference.lsl.constants', {
collapsed: true,
autogenerate: { directory: 'script/reference/lsl/constants' },
}),
]
}),
]
}),
]
})
];

/*
{
label: 'Scripting',
items: [
{ label: 'Portal', slug: 'script' },
{
label: 'Getting Started',
collapsed: false,
autogenerate: { directory: 'script/getting-started' },
},
{
label: 'Features',
collapsed: true,
autogenerate: { directory: 'script/features'}
},
{ label: 'Guides', slug: 'script/guides' },
{ label: 'Recipes', slug: 'script/recipes' },
{
label: 'SLua Language',
collapsed: false,
autogenerate: { directory: 'script/slua' },
},
{
label: 'LSL Language',
collapsed: true,
autogenerate: { directory: 'script/lsl' },
},
{

// autogenerate: { directory: 'script/reference' },
},
],
}
*/
58 changes: 58 additions & 0 deletions config/middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { defineRouteMiddleware } from '@astrojs/starlight/route-data';

// Per https://starlight-examples.netlify.app/examples/multi-sidebar/

export const onRequest = defineRouteMiddleware((context) => {
// Get the base path of the current URL
// e.g. `/product-2/some-page/` returns `/product-2/`
const currentBase = context.url.pathname.split('/').slice(0, 2).join('/') + '/';

const { pagination } = context.locals.starlightRoute;

// Filter our sidebar groups that do not include links to the current portal.
// sidebar structure is Portals -> Tabbed -> Groups/Links etc
context.locals.starlightRoute.sidebar = context.locals.starlightRoute.sidebar.filter(
// Portals
portal =>
portal.type === 'group'?
// Tabs
portal.entries.some(
tabbed =>
// Groups or Links
tabbed.type === 'group' &&
tabbed.entries.some(
entry =>
entry.type === 'group'?
entry.entries.some(
subEntry =>
subEntry.type === 'link' &&
subEntry.href.startsWith(currentBase)
)
:
entry.type === 'link' &&
entry.href.startsWith(currentBase)
)
)
:
portal.type === 'link' // Top level links
);
/*
context.locals.starlightRoute.sidebar = context.locals.starlightRoute.sidebar.filter(
(entry) =>
entry.type === 'group' &&
entry.entries.some(
(subEntry) => subEntry.type === 'link' && subEntry.href.startsWith(currentBase)
)
);
*/



// Remove pagination links across product categories.
if (pagination.prev && !pagination.prev.href.startsWith(currentBase)) {
pagination.prev = undefined;
}
if (pagination.next && !pagination.next.href.startsWith(currentBase)) {
pagination.next = undefined;
}
});
43 changes: 43 additions & 0 deletions config/sidebar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import enLabels from '../src/content/i18n/nav/en.js';

const translations = Object.entries(
import.meta.glob('../src/content/i18n/nav/*.js', { eager: true })
)
.map(([path, module]) => [path.split('/').pop()?.replace('.js', ''), module.default])
.reduce(
(translations, [lang, dict]) => {
for(const key in dict) {
translations[key] ??= {};
translations[key][lang] = dict[key];
}
return translations;
},
{}
);

export function portal(key, portal) {
if(!enLabels[key]) return new Error(`Missing label for sidebar portal key: ${key}`);
return {
label: enLabels[key],
translations: translations[key],
...portal,
};
}

export function tab(key, tab) {
if(!enLabels[key]) return new Error(`Missing label for sidebar tab key: ${key}`);
return {
label: enLabels[key],
translations: translations[key],
...tab,
};
}

export function group(key, group) {
if(!enLabels[key]) return new Error(`Missing label for sidebar group key: ${key}`);
return {
label: enLabels[key],
translations: translations[key],
...group,
};
}
Loading