From ddc0780fbde9199e73beae49d800e6355442a741 Mon Sep 17 00:00:00 2001 From: Jake Jarvis Date: Tue, 28 Sep 2021 09:33:08 -0400 Subject: [PATCH] use lit-html v2 a *little* more properly on /projects --- assets/js/src/projects.js | 63 +++++++++++++++++++-------------------- webpack.config.js | 4 +-- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/assets/js/src/projects.js b/assets/js/src/projects.js index 0aa0cd67..3a33250a 100644 --- a/assets/js/src/projects.js +++ b/assets/js/src/projects.js @@ -1,63 +1,60 @@ import fetch from "cross-fetch"; -import { html, render } from "lit-html"; +import { render } from "lit-html"; +import { html } from "lit-html/static.js"; +import { ifDefined } from "lit-html/directives/if-defined.js"; import numeral from "numeral"; import { format, formatDistanceToNowStrict, parseJSON } from "date-fns"; import twemoji from "twemoji"; // don't continue if there isn't a span#meta-hits element on this page +// TODO: be better. const wrapper = document.getElementById("github-cards"); const spinner = document.getElementById("loading-spinner"); if (wrapper) { // this is a total sh*tshow, but safer than setting one big string via innerHTML :) + // TODO: consider making this a real LitElement? const template = (repo) => html` ${repo.name} - ${(() => { - if (repo.description) { - return html`

${repo.description}

`; - } - })()} - ${(() => { - if (repo.language) { - return html`
- + ${repo.description ? html`

${repo.description}

` : null} + ${repo.language + ? html`
+ ${repo.language.name} -
`; - } - })()} - ${(() => { - if (repo.stars > 0) { - const starsComma = numeral(repo.stars).format("0,0"); - const starsPlural = repo.stars === 1 ? "star" : "stars"; - - return html`
+
` + : null} + ${repo.stars > 0 + ? html`
- ${starsComma} -
`; - } - })()} - ${(() => { - if (repo.forks > 0) { - const forksComma = numeral(repo.forks).format("0,0"); - const forksPlural = repo.forks === 1 ? "fork" : "forks"; - - return html`
+ ${numeral(repo.stars).format("0,0")} +
` + : null} + ${repo.forks > 0 + ? html`
- ${forksComma} -
`; - } - })()} + ${numeral(repo.forks).format("0,0")} +
` + : null}
diff --git a/webpack.config.js b/webpack.config.js index 8680f13a..16d7f990 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -171,8 +171,8 @@ export default { ], }, performance: { - // ignore performance hints on source maps and JSON asset manifest - assetFilter: (assetFilename) => !/\.map|\.json$/.test(assetFilename), + // only evaluate JS and CSS file sizes (ignore source maps, images, etc.) + assetFilter: (assetFilename) => /\.js$|\.css$/.test(assetFilename), }, optimization: { sideEffects: true,