fix: various small fixes
This commit is contained in:
parent
9811b42b7a
commit
e2d26a8b9a
5 changed files with 4 additions and 79 deletions
|
@ -1,6 +1,7 @@
|
|||
module.exports = {
|
||||
env: {
|
||||
node: true,
|
||||
es6: true,
|
||||
},
|
||||
extends: ["eslint:recommended", "plugin:prettier/recommended"],
|
||||
parserOptions: {
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
"postcss": "^8.4.33",
|
||||
"postcss-import": "^16.0.0",
|
||||
"postcss-import-ext-glob": "^2.1.1",
|
||||
"prettier": "3.2.4",
|
||||
"slugify": "^1.6.6"
|
||||
"prettier": "3.2.4"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
/** © Andy Bell - https://buildexcellentwebsit.es/ */
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Returns back some attributes based on wether the
|
||||
* link is active or a parent of an active item
|
||||
*
|
||||
* @param {String} itemUrl The link in question
|
||||
* @param {String} pageUrl The page context
|
||||
* @returns {String} The attributes or empty
|
||||
*/
|
||||
getLinkActiveState(itemUrl, pageUrl) {
|
||||
let response = "";
|
||||
|
||||
if (itemUrl === pageUrl) {
|
||||
response = ' aria-current="page"';
|
||||
}
|
||||
|
||||
if (itemUrl.length > 1 && pageUrl.indexOf(itemUrl) === 0) {
|
||||
response += ' data-state="active"';
|
||||
}
|
||||
|
||||
return response;
|
||||
},
|
||||
/**
|
||||
* Filters out the passed item from the passed collection
|
||||
* and randomises and limits them based on flags
|
||||
*
|
||||
* @param {Array} collection The 11ty collection we want to take from
|
||||
* @param {Object} item The item we want to exclude (often current page)
|
||||
* @param {Number} limit=3 How many items we want back
|
||||
* @param {Boolean} random=true Wether or not this should be randomised
|
||||
* @returns {Array} The resulting collection
|
||||
*/
|
||||
getSiblingContent(collection, item, limit = 3, random = true) {
|
||||
let filteredItems = collection.filter((x) => x.url !== item.url);
|
||||
|
||||
if (random) {
|
||||
let counter = filteredItems.length;
|
||||
|
||||
while (counter > 0) {
|
||||
// Pick a random index
|
||||
let index = Math.floor(Math.random() * counter);
|
||||
|
||||
counter--;
|
||||
|
||||
let temp = filteredItems[counter];
|
||||
|
||||
// Swap the last element with the random one
|
||||
filteredItems[counter] = filteredItems[index];
|
||||
filteredItems[index] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
// Lastly, trim to length
|
||||
if (limit > 0) {
|
||||
filteredItems = filteredItems.slice(0, limit);
|
||||
}
|
||||
|
||||
return filteredItems;
|
||||
},
|
||||
|
||||
/**
|
||||
* Take an array of keys and return back items that match.
|
||||
* Note: items in the collection must have a key attribute in
|
||||
* Front Matter
|
||||
*
|
||||
* @param {Array} collection 11ty collection
|
||||
* @param {Array} keys collection of keys
|
||||
* @returns {Array} result collection or empty
|
||||
*/
|
||||
filterCollectionByKeys(collection, keys) {
|
||||
return collection.filter((x) => keys.includes(x.data.key));
|
||||
},
|
||||
};
|
|
@ -42,7 +42,7 @@ const fetchRecentAlbums = async (period = "7day") => {
|
|||
const fetchRecentTracks = async () => {
|
||||
const url = `http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=wonderfulfrog&api_key=${lastFmApiKey}&format=json`;
|
||||
|
||||
const response = await EleventyFetch(url, { duration: "1m", type: "json" });
|
||||
const response = await EleventyFetch(url, { duration: "5m", type: "json" });
|
||||
const tracks = response.recenttracks.track.slice(0, 5);
|
||||
|
||||
const recentTracks = tracks.map((track) => {
|
||||
|
|
|
@ -12,7 +12,7 @@ dayjs.extend(relativeTime);
|
|||
const fetchRecentMovies = async () => {
|
||||
const url = `https://letterboxd.com/wonderfulfrog/rss/`;
|
||||
|
||||
const response = await EleventyFetch(url, { duration: "1m", type: "text" });
|
||||
const response = await EleventyFetch(url, { duration: "1d", type: "text" });
|
||||
|
||||
const $ = cheerio.load(response, { xml: true });
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue