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
13 changes: 13 additions & 0 deletions .github/workflows/landing-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ jobs:
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY || '' }}
run: npm run build

- name: Check docs llms.txt
run: |
file=landing/dist/llms.txt
if [ ! -s "$file" ]; then
echo "::error::$file is missing or empty"
exit 1
fi
count=$(grep -cE '^- \[[^]]+\]\(https://docs\.swmansion\.com/live-debugger/[^)]+\)' "$file" || true)
if [ "$count" -eq 0 ]; then
echo "::error::$file lists no pages"
exit 1
fi
echo "llms.txt lists $count pages"
- name: Publish generated content to GitHub Pages
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
Expand Down
4 changes: 3 additions & 1 deletion landing/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// @ts-check
import { defineConfig, envField, fontProviders } from "astro/config";
import swmGeo from "./swm-geo.mjs";
import react from "@astrojs/react";
import tailwindcss from "@tailwindcss/vite";

// https://astro.build/config
export default defineConfig({
integrations: [react()],
integrations: [
swmGeo({ name: "LiveDebugger", description: "LiveView debugging made simple", repository: "live-debugger" }),react()],
env: {
schema: {
ENABLE_ANALYTICS: envField.string({
Expand Down
2 changes: 2 additions & 0 deletions landing/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
import { structuredData } from '../../swm-geo.mjs';
import "../styles/global.css";
import { Font } from "astro:assets";
import { Header } from "@/components/ui/Header";
Expand Down Expand Up @@ -64,6 +65,7 @@ const enableAnalytics =
</>
)
}
<script is:inline type="application/ld+json" set:html={JSON.stringify(structuredData({ name: 'LiveDebugger', description: 'LiveView debugging made simple', repository: 'live-debugger' }))} />
</head>
<body class="font-primary">
<!-- Google Tag Manager (noscript) -->
Expand Down
129 changes: 129 additions & 0 deletions landing/swm-geo.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";

const ORGANIZATION_ID = "https://swmansion.com/#organization";

const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");

const decode = (value) =>
value
.replace(/&amp;/g, "&")
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&quot;/g, '"')
.replace(/&#(?:39|x27);/g, "'")
.trim();

// Same @id as swmansion.com, so engines read one company across both domains.
export function structuredData({ description, name, repository }) {
return {
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
"@id": ORGANIZATION_ID,
name: "Software Mansion",
url: "https://swmansion.com",
sameAs: [
"https://github.com/software-mansion",
"https://www.linkedin.com/company/software-mansion/",
"https://twitter.com/swmansion",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if it matters

Suggested change
"https://twitter.com/swmansion",
"https://x.com/swmansion",

"https://www.youtube.com/c/SoftwareMansion",
],
},
{
"@type": "SoftwareSourceCode",
name,
...(description ? { description } : {}),
...(repository
? {
codeRepository: `https://github.com/software-mansion/${repository}`,
}
: {}),
author: { "@id": ORGANIZATION_ID },
maintainer: { "@id": ORGANIZATION_ID },
},
],
};
}

function collect(dir, root = dir, found = []) {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) collect(full, root, found);
else if (entry.name.endsWith(".html") && entry.name !== "404.html")
found.push(path.relative(root, full));
}
return found;
}

export function buildLlmsTxt({ description, files, name, prefix, readFile }) {
const entries = [];

for (const file of files) {
const html = readFile(file);
const raw = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(html)?.[1] ?? "";
const title = decode(raw).replace(
new RegExp(`\\s*[|·]\\s*${escapeRegExp(name)}$`),
"",
);
if (!title) continue;

const detail = decode(
/<meta[^>]+name="description"[^>]+content="([^"]*)"/i.exec(html)?.[1] ??
"",
);
const route = file.replace(/index\.html$/, "").replace(/\.html$/, "");
entries.push(
`- [${title}](${prefix}${route})${detail ? `: ${detail}` : ""}`,
);
}

const lines = [`# ${name}`];
if (description) lines.push("", `> ${description}`);
if (entries.length) lines.push("", "## Documentation", "", ...entries.sort());
lines.push(
"",
"## About",
"",
`- [Software Mansion](https://swmansion.com): maintainer of ${name}`,
"",
);

return lines.join("\n");
}

export default function swmGeo({ description, name } = {}) {
let site = "https://docs.swmansion.com";
let base = "/";

return {
name: "swm-geo",
hooks: {
"astro:config:done": ({ config }) => {
if (config.site) site = String(config.site).replace(/\/$/, "");
base =
`/${String(config.base ?? "/").replace(/^\/|\/$/g, "")}/`.replace(
"//",
"/",
);
},
"astro:build:done": ({ dir }) => {
const outDir = fileURLToPath(dir);
fs.writeFileSync(
path.join(outDir, "llms.txt"),
buildLlmsTxt({
description,
files: collect(outDir),
name,
prefix: `${site}${base}`,
readFile: (file) =>
fs.readFileSync(path.join(outDir, file), "utf8"),
}),
"utf8",
);
},
},
};
}
Loading