Skip to content
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

Spec Generator Improvements #1

Merged
merged 2 commits into from
Mar 23, 2023
Merged
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
6 changes: 4 additions & 2 deletions lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export default class IpseityProcessor {
if (opt.page?.date) opt.lastModified = opt.page.date;
else opt.lastModified = new Date();
}
const citesFile = join(this.output, `.well-known/ipseity/references.json`);
const defsPath = join(this.output, `.well-known/ipseity/definitions/`);
const citesFile = join(this.output, `.well-known/spec-generator/references.json`);
const defsPath = join(this.output, `.well-known/spec-generator/definitions/`);
await mkdir(defsPath, { recursive: true });
const quietMode = this.quietMode;
const ctx = {
Expand Down Expand Up @@ -111,6 +111,8 @@ export default class IpseityProcessor {
const defsMeta = definitionsToWebRef(ctx.definitions, doc.title, url);
await saveJSON(ctx.citesFile, cites);
await saveJSON(join(ctx.defsPath, `${shortName}.json`), defsMeta);
const linkCanonical = doc.querySelector('link[rel=canonical]');
if (linkCanonical) linkCanonical.href = url;
return dom.serialize();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/reference-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const rel = makeRel(import.meta.url);
const webrefPath = rel('../node_modules/webref/ed/dfns/');

const definitionSources = [
'https://specs.ipfs.tech/.well-known/definitions/',
'https://specs.ipfs.tech/.well-known/spec-generator/definitions/',
];
const referenceSources = [
'https://specs.ipfs.tech/.well-known/references.json',
'https://specs.ipfs.tech/.well-known/spec-generator/references.json',
];
// these are meant to be global and used as a singleton
const allDefinitions = {};
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title></title>
<link rel="canonical">
<link rel="stylesheet" href="/css/specs.css">
<link rel="icon" href="/img/ipfs-standards.svg">
</head>
Expand Down
8 changes: 7 additions & 1 deletion test/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { JSDOM } from 'jsdom';
import makeSelectron from 'selectron-test';
import IpseityProcessor from '../lib/process.js';
import makeRel from '../lib/rel.js';
import assert from 'assert'

const rel = makeRel(import.meta.url);

Expand Down Expand Up @@ -39,6 +40,11 @@ describe('General MD/HTML Processing', function () {
selectron('h1 > code', 'fun');
selectron('title', 'The fun spec');
});
it('sets canonical link', async() => {
const doc = await md2doc('# The `fun` spec');
const link = doc.querySelector('link[rel=canonical]');
assert.equal(link.href, 'https://berjon.com/permalink');
});
it('sets the date', async () => {
const bd = '1977-03-15T08:42:00.000Z';
const doc = await md2doc('# An old doc', { lastModified: new Date(bd) });
Expand Down Expand Up @@ -100,7 +106,7 @@ describe('General MD/HTML Processing', function () {
async function md2doc (md, opt = {}) {
const template = rel('fixtures/template.html');
const output = await mkdtemp(join(tmpdir(), 'ipseity-'));
opt.page = { inputPath: output };
opt.page = { inputPath: output, url: 'permalink' };
opt.editors = [];
const ips = new IpseityProcessor({ template, output, baseURL: 'https://berjon.com/' });
const html = await ips.render(md, opt);
Expand Down
4 changes: 2 additions & 2 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Full Run', function () {
selectron('a[href="#dfn-Frontmatter"][data-dfn-type="dfn"]', 'frontmatter');
});
it('outputs references', async () => {
const refs = JSON.parse(await readFile(rel('fixtures/out/.well-known/ipseity/references.json')));
const refs = JSON.parse(await readFile(rel('fixtures/out/.well-known/spec-generator/references.json')));
const sfs = refs['spec-for-specs'];
ok(sfs, 'has a spec-for-specs entry');
equal(sfs.title, 'Spec for Specs', 'title is correct');
Expand All @@ -56,7 +56,7 @@ describe('Full Run', function () {
equal(sfs.href, 'https://berjon.com/specs/spec-for-specs/', 'href is correct');
});
it('outputs definitions', async () => {
const refs = JSON.parse(await readFile(rel('fixtures/out/.well-known/ipseity/definitions/spec-for-specs.json')));
const refs = JSON.parse(await readFile(rel('fixtures/out/.well-known/spec-generator/definitions/spec-for-specs.json')));
equal(refs.spec.title, 'Spec for Specs', 'title is correct');
equal(refs.spec.url, 'https://berjon.com/specs/spec-for-specs/', 'url is correct');
const dfns = refs.dfns.filter(d => d.id === 'dfn-spec');
Expand Down