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

have the icon processor cache them too #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
41 changes: 35 additions & 6 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const striptags = require("striptags");
const sharp = require("sharp");
const fs = require("fs");
const fetch = require("node-fetch");

function extractExcerpt(article) {
if (!article.hasOwnProperty("templateContent")) {
Expand All @@ -16,22 +19,43 @@ function extractExcerpt(article) {
.replace(/\n/g, " ")
.trim();

console.log(excerpt);

return excerpt;
}

function appIcon(value) {
async function appIcon(value) {
const data = value.data || Array.isArray(value) ? value[1] : value;
return new URL(
const iconurl = new URL(
data.icons.sort(function (a, b) {
const aN = Number(a.sizes.split("x")[0]);
const bN = Number(b.sizes.split("x")[0]);
return bN - aN;
})[0].src,
data.baseurl
).href;
return value;

if (!iconurl) {
throw Error('Could not find icon in manifest')
}

const filename = iconurl.replace(/[^a-z0-9\-]/gi, "_") + '.png';
const pathname = '/images/icon-cache/' + filename;
const localPath = __dirname + '/docs' + pathname;

if (fs.existsSync(localPath)) {
return pathname;
}

const imageBuffer = await fetch(iconurl)
.then(response => response.buffer());

await sharp(imageBuffer)
.resize(400,400,{
fit: sharp.fit.inside,
withoutEnlargement: true
})
.toFile(localPath);

return pathname;
}

module.exports = function (eleventyConfig) {
Expand All @@ -40,7 +64,12 @@ module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("styles");
eleventyConfig.setTemplateFormats("html,11ty.js,md,njk");

eleventyConfig.addFilter("appicon", appIcon);
eleventyConfig.addNunjucksAsyncFilter("appicon", function (value, callback) {
appIcon(value)
.then(path => {
callback(null, path);
});
});
eleventyConfig.addFilter("excerpt", extractExcerpt);

return {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ <h2>My installed apps</h2>
<h2>Curated apps</h2>
</header>
<div class="oui-bubble antennae-bubble"><a href="/antennae/curated apps/deno-rss/"><figure>
<img src="https://deno-rss.glitch.me/icons/icon-512x512.png" alt="app icon" width="128" height="128" style="clip-path: url(#squircle);" />
<img src="/antennae/images/icon-cache/https___deno-rss_glitch_me_icons_icon-512x512_png.png" alt="app icon" width="128" height="128" style="clip-path: url(#squircle);" />
<figcaption>RSS Reader</figcaption>
</figure></a><a href="/antennae/curated apps/racer/"><figure>
<img src="https://samsunginternet.github.io/a-frame-demos/racer/icon512.png" alt="app icon" width="128" height="128" style="clip-path: url(#squircle);" />
<img src="/antennae/images/icon-cache/https___samsunginternet_github_io_a-frame-demos_racer_icon512_png.png" alt="app icon" width="128" height="128" style="clip-path: url(#squircle);" />
<figcaption>A-Frame Racer</figcaption>
</figure></a><a href="/antennae/curated apps/Twitter/"><figure>
<img src="https://abs.twimg.com/responsive-web/client-web-legacy/icon-default-large.67500505.png" alt="app icon" width="128" height="128" style="clip-path: url(#squircle);" />
<img src="/antennae/images/icon-cache/https___abs_twimg_com_responsive-web_client-web-legacy_icon-default-large_67500505_png.png" alt="app icon" width="128" height="128" style="clip-path: url(#squircle);" />
<figcaption>Twitter</figcaption>
</figure></a></div>
</section>
Expand Down
6 changes: 3 additions & 3 deletions docs/scripts/search-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ export default {
"RSS Reader":{
"title": "RSS Reader",
"description": "RSS Reader This the app description for this test app.",
"icon": "https://deno-rss.glitch.me/icons/icon-512x512.png",
"icon": "/antennae/images/icon-cache/https___deno-rss_glitch_me_icons_icon-512x512_png.png",
"page_url": "/antennae/curated apps/deno-rss/",
"url": "https://deno-rss.glitch.me/"
},
"A-Frame Racer":{
"title": "A-Frame Racer",
"description": "A-Frame Racer This the app description for this test app.",
"icon": "https://samsunginternet.github.io/a-frame-demos/racer/icon512.png",
"icon": "/antennae/images/icon-cache/https___samsunginternet_github_io_a-frame-demos_racer_icon512_png.png",
"page_url": "/antennae/curated apps/racer/",
"url": "https://samsunginternet.github.io/a-frame-demos/racer/"
},
"Twitter":{
"title": "Twitter",
"description": "Twitter Description of Twitter",
"icon": "https://abs.twimg.com/responsive-web/client-web-legacy/icon-default-large.67500505.png",
"icon": "/antennae/images/icon-cache/https___abs_twimg_com_responsive-web_client-web-legacy_icon-default-large_67500505_png.png",
"page_url": "/antennae/curated apps/Twitter/",
"url": "https://twitter.com/"
}
Expand Down
Loading