Skip to content

Commit

Permalink
Avoid noisy diffs in the shadow repo
Browse files Browse the repository at this point in the history
This fixes a few places where site generation was non-deterministic,
causing the shadow repo's HTML output to change with every push.
  • Loading branch information
nex3 committed Jun 27, 2023
1 parent 0abfff2 commit 2d32ffc
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 4 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build:sass": "sass --style=compressed ./source/assets/sass/sass.scss:./source/assets/dist/css/sass.css ./source/assets/sass/noscript.scss:./source/assets/dist/css/noscript.css",
"watch:sass": "sass --watch ./source/assets/sass/sass.scss:./source/assets/dist/css/sass.css ./source/assets/sass/noscript.scss:./source/assets/dist/css/noscript.css",
"build-dev:scripts": "rollup -c",
"build-prod:scripts": "BABEL_ENV=production rollup -c",
"build-prod:scripts": "NODE_ENV=production BABEL_ENV=production rollup -c",
"watch:scripts": "npm run build-dev:scripts -- -w",
"build:typedoc": "./tool/typedoc-build.sh",
"build:11ty": "NODE_OPTIONS='-r ts-node/register' eleventy",
Expand Down Expand Up @@ -89,5 +89,8 @@
"ts-node": "^10.9.1",
"typescript": "^5.1.3",
"typogr": "^0.6.8"
},
"dependencies": {
"seedrandom": "^3.0.5"
}
}
16 changes: 16 additions & 0 deletions source/documentation/interpolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ interpolation in SassScript always returns an unquoted string.
[unquoted strings]: /documentation/values/strings#unquoted
[slash-separated values]: /documentation/operators/numeric#slash-separated-values

<!-- Add explicit CSS here to prevent diffs due to the use of unique-id -->

{% codeExample 'interpolation-sass-script' %}
@mixin inline-animation($duration) {
$name: inline-#{unique-id()};
Expand Down Expand Up @@ -101,6 +103,20 @@ interpolation in SassScript always returns an unquoted string.
background-color: yellow
to
background-color: red
===
.pulse {
animation-name: inline-uifpe6h;
animation-duration: 2s;
animation-iteration-count: infinite;
}
@keyframes inline-uifpe6h {
from {
background-color: yellow;
}
to {
background-color: red;
}
}
{% endcodeExample %}

{% funFact %}
Expand Down
5 changes: 4 additions & 1 deletion source/helpers/type.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import {LoremIpsum} from 'lorem-ipsum';
import seedrandom from 'seedrandom';
import truncate from 'truncate-html';
import {typogrify} from 'typogr';

import {markdownEngine} from './engines';

const lorem = new LoremIpsum();
const lorem = new LoremIpsum({
random: seedrandom("Feelin' Sassy!"),
});

/**
* Returns block of generated `lorem ipsum` text.
Expand Down
3 changes: 3 additions & 0 deletions source/source.11tydata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if (process.env.NODE_ENV === 'production') {
module.exports = {date: 'git Last Modified'};
}
44 changes: 42 additions & 2 deletions tool/typedoc-theme.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// eslint-disable-next-line node/no-missing-require
const {DefaultTheme, DefaultThemeRenderContext, JSX} = require('typedoc');
const {
DefaultTheme,
DefaultThemeRenderContext,
JSX,
UrlMapping,
// eslint-disable-next-line node/no-missing-require
} = require('typedoc');
const child_process = require('child_process');
const fs = require('fs');

function bind(fn, first) {
return (...r) => fn(first, ...r);
Expand Down Expand Up @@ -129,7 +136,40 @@ class SassSiteTheme extends DefaultTheme {
return this.contextCache;
}

getUrls(project) {
const urls = super.getUrls(project);

// Most pages in the docs have their date set based on their last git
// commit, but that doesn't work for the generated TypeDoc. To avoid having
// a bunch of churn in the sitemap for these files, we set their date to the
// last modified date for the entire directory.
if (fs.existsSync('js-api-doc')) {
const lastModified = child_process
.execSync('git log -1 --date=iso-strict --format=%cd js-api-doc', {
encoding: 'utf8',
})
.trim();
urls.push(
new UrlMapping(
'js-api.11tydata.json',
// This isn't actually based on a TypeDoc model, but if we don't
// provide a real one TypeDoc will crash. See TypeStrong/typedoc#2318.
urls[0].model,
() =>
JSON.stringify({
date: lastModified,
})
)
);
}

return urls;
}

render(page, template) {
// This is js-api.11tydata.json.
if (page.url === 'js-api.11tydata.json') return template();

const context = this.getRenderContext(page);

// The default header includes a search bar that we don't want, so we just
Expand Down

0 comments on commit 2d32ffc

Please sign in to comment.