-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add machine-readable metadata endpoints humans.txt and security.txt
#37
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eed00fd
feat: add project metadata config
toddeTV 16fcae0
feat: add text metadata route handlers
toddeTV 17231dd
feat: prerender metadata text routes
toddeTV fafd2bd
refactor: simplify humans.txt metadata
toddeTV f4932e1
feat: add author details to humans.txt
toddeTV 0b59fae
refactor: inline security.txt builder
toddeTV 873f29f
fix: align site seo name
toddeTV b156dbe
docs: add security txt jsdoc
toddeTV a424b64
docs: add humans txt jsdoc
toddeTV 76a63a6
fix: restore person-first site name
toddeTV 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { | ||
| "author": { | ||
| "contact": "hello@todde.tv", | ||
| "location": "Dresden, Germany", | ||
| "name": "Thorsten Seyschab", | ||
| "role": "IT consultant, senior full-stack developer, and conference speaker", | ||
| "sameAs": [ | ||
| "https://github.com/toddeTV/", | ||
| "https://x.com/toddeTV", | ||
| "https://bsky.app/profile/todde.tv", | ||
| "https://www.linkedin.com/in/toddetv/" | ||
| ], | ||
| "url": "https://todde.tv" | ||
| }, | ||
| "legal": { | ||
| "legalNoticePath": "/legal-notice", | ||
| "privacyPolicyPath": "/privacy-policy" | ||
| }, | ||
| "projectName": "todde.tv", | ||
| "repository": { | ||
| "licenseUrl": "https://github.com/toddeTV/todde.tv/blob/main/LICENSE.md", | ||
| "url": "https://github.com/toddeTV/todde.tv" | ||
| }, | ||
| "security": { | ||
| "contact": "mailto:hello@todde.tv", | ||
| "preferredLanguages": [ | ||
| "en", | ||
| "de" | ||
| ] | ||
| }, | ||
| "siteDescription": "Personal portfolio of Thorsten Seyschab - IT consultant, senior full-stack developer, and conference speaker.", | ||
| "siteUrl": "https://todde.tv" | ||
| } |
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,52 @@ | ||
| import projectConfig from '~~/project.config.json' | ||
|
|
||
| const defaultSecurityTxtLifetimeDays = 180 | ||
|
|
||
| interface SecurityTxtContentOptions { | ||
| canonicalUrl: string | ||
| contact: string | ||
| policyUrl?: string | ||
| preferredLanguages: string[] | ||
| } | ||
|
|
||
| /** Returns the ISO 8601 expiration timestamp for `security.txt`. */ | ||
| function createSecurityTxtExpires( | ||
| now: Date = new Date(), | ||
| lifetimeDays: number = defaultSecurityTxtLifetimeDays, | ||
| ): string { | ||
| const expiresAt = new Date(now.getTime()) | ||
|
|
||
| expiresAt.setUTCDate(expiresAt.getUTCDate() + lifetimeDays) | ||
|
|
||
| return expiresAt.toISOString() | ||
| } | ||
|
|
||
| /** Builds the plain text `security.txt` response body from route metadata. */ | ||
| function buildSecurityTxtContent( | ||
| options: SecurityTxtContentOptions, | ||
| now: Date = new Date(), | ||
| ): string { | ||
| const lines = [ | ||
| `Contact: ${options.contact}`, | ||
| `Expires: ${createSecurityTxtExpires(now)}`, | ||
| `Canonical: ${options.canonicalUrl}`, | ||
| `Preferred-Languages: ${options.preferredLanguages.join(', ')}`, | ||
| ] | ||
|
|
||
| if (options.policyUrl) { | ||
| lines.push(`Policy: ${options.policyUrl}`) | ||
| } | ||
|
|
||
| return `${lines.join('\n')}\n` | ||
| } | ||
|
|
||
| export default defineEventHandler((event) => { | ||
| const content = buildSecurityTxtContent({ | ||
| canonicalUrl: new URL('/.well-known/security.txt', projectConfig.siteUrl).toString(), | ||
| contact: projectConfig.security.contact, | ||
| preferredLanguages: projectConfig.security.preferredLanguages, | ||
| }) | ||
|
|
||
| setResponseHeader(event, 'Content-Type', 'text/plain; charset=utf-8') | ||
| return content | ||
| }) |
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,36 @@ | ||
| import projectConfig from '~~/project.config.json' | ||
|
|
||
| /** Returns the plain text `humans.txt` response using `projectConfig`, `useRuntimeConfig`, and `setResponseHeader`. */ | ||
| export default defineEventHandler((event) => { | ||
| const { author, legal, projectName, repository, siteDescription, siteUrl } = projectConfig | ||
| const legalNoticeUrl = new URL(legal.legalNoticePath, siteUrl).toString() | ||
| const privacyPolicyUrl = new URL(legal.privacyPolicyPath, siteUrl).toString() | ||
| const runtimeConfig = useRuntimeConfig(event) | ||
| const authorProfiles = author.sameAs.map(profileUrl => ` Profile: ${profileUrl}`) | ||
|
|
||
| const content = [ | ||
| '# humanstxt.org/', | ||
| '', | ||
| '/* PROJECT */', | ||
| ` Name: ${projectName}`, | ||
| ` Version: ${runtimeConfig.public.build.releaseLabel}`, | ||
| ` URL: ${siteUrl}`, | ||
| ` Description: ${siteDescription}`, | ||
| ` Legal Notice: ${legalNoticeUrl}`, | ||
| ` Privacy Policy: ${privacyPolicyUrl}`, | ||
| '', | ||
| '/* AUTHOR */', | ||
| ` Name: ${author.name}`, | ||
| ` Role: ${author.role}`, | ||
| ` Contact: ${author.contact}`, | ||
| ` Website: ${author.url}`, | ||
| ...authorProfiles, | ||
| '', | ||
| '/* SOURCE CODE */', | ||
| ` Repository: ${repository.url}`, | ||
| ` License: ${repository.licenseUrl}`, | ||
| ].join('\n') | ||
|
|
||
| setResponseHeader(event, 'Content-Type', 'text/plain; charset=utf-8') | ||
| return `${content}\n` | ||
| }) |
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.