Repository navigation
docs(site): improve technical discovery and canonical metadata #569
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
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
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
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,58 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { readFileSync } from 'node:fs'; | ||
| import test from 'node:test'; | ||
|
|
||
| const buildRoot = new URL('../../build_production/', import.meta.url); | ||
| const html = (path) => readFileSync(new URL(path, buildRoot), 'utf8'); | ||
| const tags = (page, name) => [...page.matchAll(new RegExp('<' + name + '\\b[^>]*>', 'gi'))].map((match) => match[0]); | ||
| const attribute = (tag, name) => tag?.match(new RegExp('\\b' + name + '="([^"]*)"', 'i'))?.[1] ?? null; | ||
| const namedTag = (page, element, attributeName, value) => | ||
| tags(page, element).find((tag) => attribute(tag, attributeName) === value); | ||
|
|
||
| test('generated pages have absolute canonical, hreflang and social image URLs', () => { | ||
| for (const path of [ | ||
| 'index.html', | ||
| 'faq/index.html', | ||
| 'tecnical-details/index.html', | ||
| 'pt-BR/tecnical-details/index.html', | ||
| ]) { | ||
| const page = html(path); | ||
| const canonical = attribute(namedTag(page, 'link', 'rel', 'canonical'), 'href'); | ||
| assert.match(canonical ?? '', /^https:\/\//, path + ': canonical must be absolute'); | ||
| const canonicalOrigin = new URL(canonical).origin; | ||
|
|
||
| const alternates = tags(page, 'link').filter((tag) => | ||
| attribute(tag, 'rel') === 'alternate' && attribute(tag, 'hreflang')); | ||
| assert.ok(alternates.length > 0, path + ': missing hreflang'); | ||
| for (const alternate of alternates) { | ||
| assert.match(attribute(alternate, 'href') ?? '', /^https:\/\//, path + ': hreflang must be absolute'); | ||
| } | ||
|
|
||
| for (const [name, key] of [['og:image', 'property'], ['twitter:image', 'name']]) { | ||
| const image = attribute(namedTag(page, 'meta', key, name), 'content'); | ||
| assert.match(image ?? '', /^https:\/\//, path + ': ' + name + ' must be absolute'); | ||
| assert.equal(new URL(image).origin, canonicalOrigin, path + ': ' + name + ' must use the site origin'); | ||
| assert.match(new URL(image).pathname, /\/assets\/images\/logo\/logo-libresign-large\.png$/); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| test('rendered technical guide links are styled and external docs open safely', () => { | ||
| for (const path of ['index.html', 'faq/index.html', 'tecnical-details/index.html']) { | ||
| const anchors = tags(html(path), 'a'); | ||
| assert.ok(anchors.some((tag) => | ||
| /posts\/libresign-api-guide/.test(attribute(tag, 'href') ?? '') && | ||
| /\bud-btn-solid-brand\b/.test(attribute(tag, 'class') ?? '') | ||
| ), path + ': missing styled API guide action'); | ||
| } | ||
|
|
||
| for (const path of ['faq/index.html', 'tecnical-details/index.html']) { | ||
| const anchors = tags(html(path), 'a'); | ||
| assert.ok(anchors.some((tag) => | ||
| attribute(tag, 'href') === 'https://docs.libresign.coop/' && | ||
| /\bud-btn-outline-brand\b/.test(attribute(tag, 'class') ?? '') && | ||
| attribute(tag, 'target') === '_blank' && | ||
| attribute(tag, 'rel') === 'noopener noreferrer' | ||
| ), path + ': missing safely opened documentation action'); | ||
| } | ||
| }); |
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,30 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { readFileSync } from 'node:fs'; | ||
| import test from 'node:test'; | ||
|
|
||
| const read = (name) => readFileSync(new URL('../../source/' + name, import.meta.url), 'utf8'); | ||
| const header = read('_layouts/header.blade.php'); | ||
| const home = read('index.blade.php'); | ||
| const technical = read('tecnical-details.blade.php'); | ||
| const faq = read('faq.blade.php'); | ||
| const layout = read('_layouts/main.blade.php'); | ||
|
|
||
| test('primary discovery paths reference the API guide and documentation chooser', () => { | ||
| for (const [name, source] of [['header', header], ['home', home], ['technical', technical], ['FAQ', faq]]) { | ||
| assert.match(source, /posts\/libresign-api-guide/, name + ' lacks an API guide link'); | ||
| } | ||
| for (const [name, source] of [['header', header], ['technical', technical], ['FAQ', faq]]) { | ||
| assert.match(source, /https:\/\/docs\.libresign\.coop\//, name + ' lacks a documentation chooser'); | ||
| } | ||
| assert.doesNotMatch(technical, /docs\.libresign\.coop\/(?:developer_manual|admin_manual)\//); | ||
| }); | ||
|
|
||
| test('social image URLs use the origin resolver even with production baseUrl="/"', () => { | ||
| assert.match(layout, /property="og:image" content="\{\{\s*\$absoluteSeoUrl\(/); | ||
| assert.match(layout, /name="twitter:image" content="\{\{\s*\$absoluteSeoUrl\(/); | ||
| }); | ||
|
|
||
| test('new technical links use the Weblate extraction helper', () => { | ||
| assert.match(technical, /id="it-requirements-heading">\{\{\s*\$page->t\(/); | ||
| assert.match(faq, /https:\/\/docs\.libresign\.coop\/"[^>]*>\{\{\s*\$page->t\(/); | ||
| }); |
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.