-
Notifications
You must be signed in to change notification settings - Fork 66
Add JSON-LD and llms.txt for AI search #782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
exploIF
merged 8 commits into
software-mansion:main
from
halskiszymon:geo-structured-data
Aug 24, 2026
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
81e86cb
Add JSON-LD and a build-time llms.txt for the docs
halskiszymon 8e20db6
Drop a stray blank line in the plugins list
halskiszymon a979dc2
Fix the llms.txt path: the job already runs inside the docs directory
halskiszymon e577f95
Escape the site title before using it in a regex
halskiszymon 59ef832
Terminate the workflow file with a newline
halskiszymon e6ea243
Group docs pages by folder and escape the JSON-LD
halskiszymon ae7dce7
Drop the section names that were doing nothing
halskiszymon 158e7f0
Drop the comment restating the commit message
halskiszymon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| const fs = require('node:fs'); | ||
| const path = require('node:path'); | ||
|
|
||
| const ORGANIZATION_ID = 'https://swmansion.com/#organization'; | ||
| const SECTIONS = { docs: 'Documentation', blog: 'Blog', examples: 'Examples' }; | ||
|
|
||
|
exploIF marked this conversation as resolved.
|
||
| const decode = (value) => | ||
| value | ||
| .replace(/&/g, '&') | ||
| .replace(/</g, '<') | ||
| .replace(/>/g, '>') | ||
| .replace(/"/g, '"') | ||
| .replace(/&#(?:39|x27);/g, "'") | ||
| .trim(); | ||
|
|
||
| const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
|
|
||
| const metaOf = (html, name) => | ||
| new RegExp( | ||
| `<meta[^>]+name="${escapeRegExp(name)}"[^>]+content="([^"]*)"`, | ||
| 'i', | ||
| ).exec(html)?.[1] ?? ''; | ||
|
|
||
| function describe(html, siteTitle) { | ||
| const raw = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(html)?.[1] ?? ''; | ||
| const title = decode(raw).replace( | ||
| new RegExp(`\\s*\\|\\s*${escapeRegExp(siteTitle)}$`), | ||
| '', | ||
| ); | ||
| return { title, description: decode(metaOf(html, 'description')) }; | ||
| } | ||
|
|
||
| // Same @id as swmansion.com, so engines read one company across both domains. | ||
| function buildStructuredData(siteConfig) { | ||
| const { organizationName, projectName, tagline, title } = siteConfig; | ||
| const repository = | ||
| organizationName && projectName | ||
| ? `https://github.com/${organizationName}/${projectName}` | ||
| : undefined; | ||
|
|
||
| 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', | ||
| 'https://www.youtube.com/c/SoftwareMansion', | ||
| ], | ||
| }, | ||
| { | ||
| '@type': 'SoftwareSourceCode', | ||
| name: title, | ||
| ...(tagline ? { description: tagline } : {}), | ||
| ...(repository ? { codeRepository: repository } : {}), | ||
| author: { '@id': ORGANIZATION_ID }, | ||
| maintainer: { '@id': ORGANIZATION_ID }, | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
|
|
||
| function buildLlmsTxt({ siteConfig, routesPaths, readPage }) { | ||
| const { baseUrl, title, tagline, url } = siteConfig; | ||
| const grouped = new Map(); | ||
|
|
||
| for (const route of routesPaths) { | ||
| if (!route.startsWith(baseUrl) || route.endsWith('404.html')) continue; | ||
|
|
||
| const relative = route.slice(baseUrl.length); | ||
| const html = readPage(relative); | ||
| if (!html) continue; | ||
|
|
||
| const page = describe(html, title); | ||
| if (!page.title) continue; | ||
|
|
||
| const section = SECTIONS[relative.split('/')[0]] ?? 'Pages'; | ||
| const line = `- [${page.title}](${url.replace(/\/$/, '')}${route})${page.description ? `: ${page.description}` : ''}`; | ||
|
|
||
| if (!grouped.has(section)) grouped.set(section, []); | ||
| grouped.get(section).push(line); | ||
| } | ||
|
|
||
| const lines = [`# ${title}`]; | ||
| if (tagline) lines.push('', `> ${tagline}`); | ||
|
|
||
| for (const section of ['Documentation', 'Examples', 'Blog', 'Pages']) { | ||
| const entries = grouped.get(section); | ||
| if (!entries?.length) continue; | ||
| lines.push('', `## ${section}`, '', ...entries.sort()); | ||
| } | ||
|
|
||
| lines.push( | ||
| '', | ||
| '## About', | ||
| '', | ||
| `- [Software Mansion](https://swmansion.com): maintainer of ${title}`, | ||
| '', | ||
| ); | ||
|
|
||
| return lines.join('\n'); | ||
| } | ||
|
|
||
| module.exports = function swmGeoPlugin(context) { | ||
| return { | ||
| name: 'swm-geo', | ||
|
|
||
| injectHtmlTags() { | ||
| return { | ||
| headTags: [ | ||
| { | ||
| tagName: 'script', | ||
| attributes: { type: 'application/ld+json' }, | ||
| innerHTML: JSON.stringify(buildStructuredData(context.siteConfig)), | ||
| }, | ||
|
halskiszymon marked this conversation as resolved.
|
||
| ], | ||
| }; | ||
| }, | ||
|
|
||
| async postBuild({ siteConfig, routesPaths, outDir }) { | ||
| const readPage = (relative) => { | ||
| const file = path.join(outDir, relative, 'index.html'); | ||
| return fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : ''; | ||
| }; | ||
|
|
||
| await fs.promises.writeFile( | ||
| path.join(outDir, 'llms.txt'), | ||
| buildLlmsTxt({ siteConfig, routesPaths, readPage }), | ||
| 'utf8', | ||
| ); | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| module.exports.buildLlmsTxt = buildLlmsTxt; | ||
| module.exports.buildStructuredData = buildStructuredData; | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.