diff --git a/src/bloggers.11tydata.js b/src/bloggers.11tydata.js new file mode 100644 index 0000000..ce871aa --- /dev/null +++ b/src/bloggers.11tydata.js @@ -0,0 +1,44 @@ +"use strict"; + +const path = require("path"); +const fs = require("fs"); + +const fetch_json = require("./lib/fetch_json.js"); + +async function fetch_info(blogger) { + if(typeof blogger.github_username !== "string") return; + + const github_userdata = (await fetch_json(`https://api.github.com/users/${blogger.github_username}`)).body; + + if(typeof github_userdata.message === "string") { + console.error(github_userdata.message); + } + + console.log(`GITHUB_USERDATA`, github_userdata) + + blogger.bio = github_userdata.bio; + blogger.url_blog = github_userdata.blog; + blogger.url_github = github_userdata.html_url; + blogger.url_twitter = github_userdata.twitter_username === null ? null : `https://twitter.com/@${github_userdata.twitter_username.replace(/^@/, "")}`; + blogger.url_avatar = github_userdata.avatar_url; + + + if(typeof blogger.url_blog !== "string" || blogger.url_blog.length == 0) + blogger.url_blog = null; +} + +module.exports = async function() { + const feeds_data = JSON.parse(await fs.promises.readFile(path.resolve(__dirname, "../feeds.json"), "utf-8")); + + + + await Promise.all(feeds_data.map(fetch_info)); + + return { + layout: "main.njk", + title: "Bloggers", + tags: "navigable", + date: "2001-01-01", + bloggers: feeds_data + } +} \ No newline at end of file diff --git a/src/bloggers.html b/src/bloggers.html new file mode 100644 index 0000000..a413b0c --- /dev/null +++ b/src/bloggers.html @@ -0,0 +1,25 @@ +

Check out these cool people who are featured here on hullblogs.com!

+ +
+ {% for blogger in bloggers %} +
+ {{ blogger.author_name | htmlentities }} + {{ blogger.author_name | htmlentities }} + + {% if blogger.url_blog %} + {{ blogger.author_name | htmlentities }}'s blog + {% endif %} + + {{ blogger.author_name | htmlentities }}'s blog feed + + + {{ blogger.author_name | htmlentities }}'s GitHub account + + {% if blogger.url_twitter %} + {{ blogger.author_name | htmlentities }}'s GitHub account + {% endif %} + + {{ blogger.bio | htmlentities }} +
+ {% endfor %} +
\ No newline at end of file diff --git a/src/images/rss.svg b/src/images/rss.svg new file mode 100644 index 0000000..4f1c279 --- /dev/null +++ b/src/images/rss.svg @@ -0,0 +1 @@ + diff --git a/src/images/twitter.svg b/src/images/twitter.svg new file mode 100644 index 0000000..59c727f --- /dev/null +++ b/src/images/twitter.svg @@ -0,0 +1,65 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/lib/fetch_json.js b/src/lib/fetch_json.js new file mode 100644 index 0000000..aa075bc --- /dev/null +++ b/src/lib/fetch_json.js @@ -0,0 +1,23 @@ +const fs = require("fs"); +const path = require("path"); +const os = require("os"); + +const phin = require("phin"); + +async function fetch_json(url) { + let package = JSON.parse(await fs.promises.readFile( + path.join(path.dirname(path.dirname(__dirname)), "package.json"), "utf8" + )); + + return (await phin({ + url, + headers: { + "user-agent": `HullBlogsStaticBuilder/${package.version} (Node.js/${process.version}; ${os.platform()} ${os.arch()}) eleventy/${package.dependencies["@11ty/eleventy"].replace(/\^/, "")}` + }, + followRedirects: true, + parse: "json" + })); +} + + +module.exports = fetch_json;