Skip to content

Commit

Permalink
Merge pull request #305 from photogabble/feature/304-refactor-dir-str…
Browse files Browse the repository at this point in the history
…ucture

Refactor directory structure
  • Loading branch information
carbontwelve authored Dec 13, 2023
2 parents 50c595f + 45eb652 commit a9e8608
Show file tree
Hide file tree
Showing 1,231 changed files with 267 additions and 183 deletions.
45 changes: 27 additions & 18 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const filters = require('./utils/filters')
const collections = require('./utils/collections');
const {slugify} = require('./utils/filters');
const shortcodes = require('./utils/shortcodes');
const transforms = require('./utils/transforms');
const ObjectCache = require("./utils/helpers/cache");
const filters = require('./lib/filters')
const collections = require('./lib/collections');
const {slugify} = require('./lib/filters');
const shortcodes = require('./lib/shortcodes');
const transforms = require('./lib/transforms');
const ObjectCache = require("./lib/helpers/cache");

module.exports = function (eleventyConfig) {
eleventyConfig.setUseGitIgnore(false);
Expand All @@ -12,20 +12,20 @@ module.exports = function (eleventyConfig) {
// Install Plugins
//

eleventyConfig.addPlugin(require('./utils/helpers/screenshot'));
eleventyConfig.addPlugin(require('./lib/helpers/screenshot'));

eleventyConfig.addPlugin(require('@photogabble/eleventy-plugin-interlinker'), {
defaultLayout: 'layouts/embed.liquid',
});

eleventyConfig.addPlugin(require('@photogabble/eleventy-plugin-font-subsetting'), {
srcFiles: [
`./_assets/fonts/iosevka-etoile-regular.woff2`,
`./_assets/fonts/iosevka-etoile-italic.woff2`,
`./_assets/fonts/iosevka-etoile-bold.woff2`,
`./_assets/fonts/iosevka-etoile-bolditalic.woff2`,
`./public/fonts/iosevka-etoile-regular.woff2`,
`./public/fonts/iosevka-etoile-italic.woff2`,
`./public/fonts/iosevka-etoile-bold.woff2`,
`./public/fonts/iosevka-etoile-bolditalic.woff2`,
],
dist: './fonts',
dist: './src/fonts',
enabled: process.env.ELEVENTY_ENV !== 'production',
cache: new ObjectCache('font-subsetting'),
});
Expand All @@ -35,7 +35,8 @@ module.exports = function (eleventyConfig) {
similar: {
'Game Development': ['GameDev'],
'Retro Computing': ['RetroComputing'],
'Node JS': ['Node']
'Node JS': ['Node'],
'365 Day Project': ['365DayProject']
},
slugify,
});
Expand Down Expand Up @@ -110,17 +111,25 @@ module.exports = function (eleventyConfig) {
//

eleventyConfig.addPassthroughCopy({
'_assets/favicon': '/',
'_assets/files': 'files',
'img': './img',
'public/favicon': '/',
'public/files': 'files',
'public/img': 'img',
'_redirects': '_redirects',
'_assets/og-image': 'img/og-image',
'public/og-image': 'img/og-image',
'public/main.js': 'main.js',
});

//
// Markdown-It && Plugins
//

eleventyConfig.setLibrary('md', require('./utils/helpers/markdown'));
eleventyConfig.setLibrary('md', require('./lib/helpers/markdown'));

return {
dir: {
input: "src",
output: "_site"
}
};

};
4 changes: 2 additions & 2 deletions .eleventyignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
styles/components
functions/_posts
functions/_posts.json
public
.cache
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
_site/
dist/
_tmp/
.DS_Store
node_modules/
.idea
.cache
functions/_posts.json
functions/_posts
.cache
2 changes: 1 addition & 1 deletion bin/add-bookmark.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const {Select, Input, Confirm} = require('enquirer');
const {slugify} = require("../utils/filters");
const {slugify} = require("../lib/filters");
const {DateTime} = require('luxon');
const fetch = require("node-fetch");
const cheerio = require('cheerio');
Expand Down
4 changes: 2 additions & 2 deletions functions/create-og-images.js → bin/create-og-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ const fileReadable = (path) => {

(async () => {
try {
let posts = require("./_posts.json");
let posts = require("../.cache/_posts.json");
const promises = [];

posts = posts.map((post) => {
return {
...post,
src: path.join(process.cwd(), post.template),
dist: path.join(process.cwd(), `_assets/og-image/${post.slug}.jpg`),
dist: path.join(process.cwd(), `public/og-image/${post.slug}.jpg`),
};
}).filter((post) => !(fileReadable(post.dist) === true || fileReadable(post.src) === false))

Expand Down
20 changes: 0 additions & 20 deletions functions/get-git-changes.js

This file was deleted.

8 changes: 4 additions & 4 deletions utils/collections.js → lib/collections.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {setupMarkdownIt, parseCollectionHashtags} = require ('./helpers/hashtags');
const {chunk} = require('./helpers')
const {slugify, padStart, specialTagMeta} = require("./filters");
const listData = require('../_data/lists-meta');
const listData = require('../src/_data/lists-meta');

// This function returns a reducer function for paginating custom taxonomy such as
// the content types used in this digital garden.
Expand Down Expand Up @@ -45,8 +45,8 @@ const md = setupMarkdownIt(require('markdown-it')());
module.exports = function loadCollection(eleventyConfig) {
// Filter draft posts when deployed into production
const post = (collection) => ((process.env.ELEVENTY_ENV !== 'production')
? [...collection.getFilteredByGlob('./content/**/*.md')]
: [...collection.getFilteredByGlob('./content/**/*.md')].filter((post) => !post.data.draft)
? [...collection.getFilteredByGlob('./src/content/**/*.md')]
: [...collection.getFilteredByGlob('./src/content/**/*.md')].filter((post) => !post.data.draft)
).map(parseCollectionHashtags(md, eleventyConfig.globalData.tagAtlas));

// Written for #20, this creates a collection of all tags
Expand Down Expand Up @@ -176,7 +176,7 @@ module.exports = function loadCollection(eleventyConfig) {
return carry;
}, new Map()).values());

const nowUpdates = (collection) => [...collection.getFilteredByGlob('./now/*.md')
const nowUpdates = (collection) => [...collection.getFilteredByGlob('./src/now/*.md')
.filter((post) => !post.data.draft)];

const collectSpecialTaggedContent = (prefix, collection) => Array.from(
Expand Down
4 changes: 2 additions & 2 deletions utils/filters.js → lib/filters.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {toTitleCase, strToSlug} = require('./helpers');
const metadata = require('../_data/metadata');
const listData = require('../_data/lists-meta');
const metadata = require('../src/_data/metadata');
const listData = require('../src/_data/lists-meta');
const readingTime = require('reading-time');
const {DateTime} = require('luxon');
const path = require('path');
Expand Down
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions lib/helpers/get-git-changes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const git = require('simple-git')();
const ObjectCache = require("./cache");
const {DateTime} = require('luxon');
const chalk = require("chalk");

let cache;
async function initCache() {
console.log(chalk.blue('[@photogabble/git-history]'), 'Loading Cache');
const gitHash = await git.revparse( ['--short', 'HEAD']);
cache = new ObjectCache(`git-${gitHash}`);
}

async function getChanges(data) {
if (!cache) await initCache();
const filePathname = data.page.inputPath;
if (cache.has(filePathname)) return cache.get(filePathname);

console.log(chalk.blue('[@photogabble/git-history]'), 'Fetching git history for: [' + chalk.green(filePathname) + ']');

try {
const history = await git.log({file: filePathname});
const mapped = history.all.map(el =>( {
...el,
date: DateTime.fromISO(el.date).toLocaleString(DateTime.DATE_FULL),
url: `https://github.com/photogabble/website/commit/${encodeURIComponent(el.hash)}`
}));
cache.set(filePathname, mapped, cache.forever);
return mapped;
} catch (e) {
return null;
}
}

module.exports = {
getChanges
}
2 changes: 1 addition & 1 deletion utils/helpers/hashtags.js → lib/helpers/hashtags.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
});

md.renderer.rules.hashtag_open = (tokens, idx) =>
`<a href="/topic/${atlas().find(tokens[idx].content).slug}" class="tag">`;
`<a href="/topic/${atlas().findOrCreateByTitle(tokens[idx].content).slug}" class="tag">`;

return md;
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion utils/helpers/screenshot.js → lib/helpers/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const variableHash = (data, size = 5, encoding = 'hex') => {
* @param { * } customOptions
*/
module.exports = function (eleventyConfig, customOptions = {}) {
const distFolder = path.join(process.cwd(), `img/bookmarks`);
const distFolder = path.join(process.cwd(), `public/img/bookmarks`);
const viewport = [1200, 630];
const timeout = 8500;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion og/og-image.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pagination:
data: collections.post
size: 1
alias: article
permalink: functions/_posts/{{ article.data.title | slugify }}/og-image.html
permalink: .cache/_posts/{{ article.data.title | slugify }}/og-image.html
permalinkBypassOutputDir: true
eleventyExcludeFromCollections: true
---
Expand Down
4 changes: 2 additions & 2 deletions og/og-posts.njk
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: "Open Graph: posts.json"
permalink: functions/_posts.json
permalink: .cache/_posts.json
permalinkBypassOutputDir: true
eleventyExcludeFromCollections: true
---
[{% for post in collections.post %}
{
"slug":"{{ post.data.title | slugify }}",
"template":"functions/_posts/{{ post.data.title | slugify }}/og-image.html"
"template":".cache/_posts/{{ post.data.title | slugify }}/og-image.html"
}{% if not loop.last %},{% endif %}
{% endfor %}]
21 changes: 11 additions & 10 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
"serve:prod": "rm -rf _site && cross-env ELEVENTY_ENV=production eleventy --serve",
"build": "cross-env ELEVENTY_ENV=production eleventy",
"build:dev": "cross-env ELEVENTY_ENV=development eleventy",
"og-images": "node functions/create-og-images.js",
"og-images": "node ./bin/create-og-images.js",
"make:bookmark": "node ./bin/add-bookmark.js"
},
"bin": {
"add-bookmark": "./bin/add-bookmark.js"
"add-bookmark": "./bin/add-bookmark.js",
"gen-og-images": "./bin/create-og-images.js"
},
"keywords": [
"PhotoGabble",
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading

0 comments on commit a9e8608

Please sign in to comment.