Skip to content

Commit

Permalink
Merge pull request #10 from buzcarter/feature/lets_import_for_fun
Browse files Browse the repository at this point in the history
Feature/lets import for fun
  • Loading branch information
buzcarter committed Nov 12, 2023
2 parents efe7653 + 7a8a2d9 commit 22695ad
Show file tree
Hide file tree
Showing 23 changed files with 2,312 additions and 364 deletions.
64 changes: 0 additions & 64 deletions .eslintrc

This file was deleted.

44 changes: 44 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* eslint-disable no-unused-vars, no-multi-spaces */
const OFF = 0;
const WARNING = 1;
const ERROR = 2;
/* eslint-enable no-unused-vars, no-multi-spaces */

module.exports = {
env: {
amd: true,
browser: true,
// commonjs,
// es6: true,
// node: true,
},
extends: [
'./node_modules/eslint-config-airbnb-base/rules/best-practices',
'./node_modules/eslint-config-airbnb-base/rules/errors',
'./node_modules/eslint-config-airbnb-base/rules/node',
'./node_modules/eslint-config-airbnb-base/rules/style',
'./node_modules/eslint-config-airbnb-base/rules/variables',
'./node_modules/eslint-config-airbnb-base/rules/es6',
'./node_modules/eslint-config-airbnb-base/rules/strict',
].map(require.resolve),
parserOptions: {
ecmaVersion: 'latest',
// sourceType: 'commonjs',
},
globals: {},
rules: {
'default-case': OFF,
'function-paren-newline': OFF,
'max-len': OFF,
'no-param-reassign': OFF,
'no-plusplus': OFF,
'no-underscore-dangle': OFF,
'no-use-before-define': OFF,
'object-curly-newline': [ERROR, {
ImportDeclaration: {
multiline: true,
minProperties: 5,
},
}],
},
};
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ node_modules
output
*.zip
*.rar
recipeIndex.bundle.js
recipeIndex.bundle.js.map
50 changes: 28 additions & 22 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
/* eslint-disable no-console */
const { basename, extname, join, resolve } = require('path');
const { rmSync, mkdirSync, rename } = require('fs');
const { cp, readdir, readFile } = require('fs/promises');
const sharp = require('sharp');
import {
basename, dirname, extname, join, resolve,
} from 'path';
import { rmSync, mkdirSync, rename } from 'fs';
import { cp, readdir, readFile } from 'fs/promises';
import sharp from 'sharp';
import { fileURLToPath } from 'url';

const { buildRecipes } = require('./src/buildRecipes');
const buildRecipeIndex = require('./src/buildRecipeIndex');
const configs = require('./config');
export const __dirname = dirname(fileURLToPath(import.meta.url));

import buildRecipes from './src/buildRecipes.js';
import buildRecipeIndex from './src/buildRecipeIndex.js';
import configs from './config.js';

const THUMBNAIL_WIDTH = 260;

const filterByExtension = (fileList, basePath, allowedExtensions) => fileList
.filter(fileName => allowedExtensions.includes(extname(fileName)))
.map(fileName => ({
.filter((fileName) => allowedExtensions.includes(extname(fileName)))
.map((fileName) => ({
file: resolve(basePath, fileName),
fileName,
name: basename(fileName, extname(fileName)),
Expand All @@ -31,13 +36,13 @@ function changeExtension(mdDestinationPath) {
return new Promise((promResolve) => {
readdir(mdDestinationPath)
.then((filelist) => {
const onError = e => e && console.log(e);
const onError = (e) => e && console.log(e);
filelist.forEach((file) => {
if (extname(file) !== '.md') {
return;
}
const originalPath = join(mdDestinationPath, file);
const newPath = join(mdDestinationPath, basename(file, '.md') + '.txt');
const newPath = join(mdDestinationPath, `${basename(file, '.md')}.txt`);
rename(originalPath, newPath, onError);
});
})
Expand All @@ -57,11 +62,11 @@ function legacyImageType(imgDestinationPath) {
return;
}
const originalPath = join(imgDestinationPath, file);
const imgPath = join(imgDestinationPath, basename(file, '.avif') + '.jpg');
const imgPath = join(imgDestinationPath, `${basename(file, '.avif')}.jpg`);
sharp(originalPath)
.jpeg({ quality: 70 })
.toFile(imgPath)
.catch(err => console.error(`Problem generating ${imgPath}`, err));
.catch((err) => console.error(`Problem generating ${imgPath}`, err));
});
})
.then(() => {
Expand All @@ -73,12 +78,13 @@ function legacyImageType(imgDestinationPath) {
function swapJpegForAvif(images) {
images
.filter(({ fileName }) => extname(fileName) === '.avif')
.forEach(img => img.fileName = img.fileName.replace(/avif$/, 'jpg'));
// eslint-disable-next-line no-return-assign
.forEach((img) => img.fileName = img.fileName.replace(/avif$/, 'jpg'));

return images;
}

function copyStatic({staticPath, imagesPath, outputPath, recipesPath}) {
function copyStatic({ staticPath, imagesPath, outputPath, recipesPath }) {
const mdDestinationPath = resolve(outputPath, 'sources');
const imgDestinationPath = resolve(outputPath, 'images');

Expand All @@ -104,7 +110,7 @@ function makeThumbnails(outputPath, images) {
.resize(THUMBNAIL_WIDTH)
.jpeg({ quality: 70 })
.toFile(thumbnailPath)
.catch(err => console.error(`Problem generating ${thumbnailPath}`, err));
.catch((err) => console.error(`Problem generating ${thumbnailPath}`, err));
});
}

Expand Down Expand Up @@ -133,16 +139,16 @@ function getCommanLineOverrides(args) {
return cmdArgs;
}

function main(configs) {
function main(opts) {
const startTime = new Date();
const imagesPath = resolve(__dirname, configs.imageDir);
const outputPath = resolve(__dirname, configs.outputDir);
const recipesPath = resolve(__dirname, configs.recipeDir);
const imagesPath = resolve(__dirname, opts.imageDir);
const outputPath = resolve(__dirname, opts.outputDir);
const recipesPath = resolve(__dirname, opts.recipeDir);
const staticPath = resolve(__dirname, './src/static/');
const templatesPath = resolve(__dirname, './src/templates/');

const options = {
...configs,
...opts,
imagesPath,
outputPath,
recipesPath,
Expand All @@ -161,7 +167,7 @@ function main(configs) {
images = filterByExtension(images, imagesPath, ['.jpg', '.jpeg', '.png', '.webp', '.avif']);

setupOutputDir(outputPath);
copyStatic({staticPath, imagesPath, outputPath, recipesPath});
copyStatic({ staticPath, imagesPath, outputPath, recipesPath });
makeThumbnails(outputPath, images);
images = swapJpegForAvif(images);

Expand Down
12 changes: 6 additions & 6 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const yelpLocation = 'Bloomfield, NJ'; // no need for fancy formatting, just do
* (these are mostly things that folks might want to change, but
* of course you can customize the code too)
*/
module.exports = {
export default {
imageDir: './images',
outputDir: './output',
recipeDir: './recipes',
Expand Down Expand Up @@ -53,20 +53,20 @@ module.exports = {
*/
helpURLs: [{
label: 'Image search',
url: `https://www.google.com/search?q=${RECIPE_NAME}&tbm=isch`
url: `https://www.google.com/search?q=${RECIPE_NAME}&tbm=isch`,
},
{
label: 'Serious Eats',
url: `https://www.seriouseats.com/search?q=${RECIPE_NAME}&site=recipes`
url: `https://www.seriouseats.com/search?q=${RECIPE_NAME}&site=recipes`,
},
{
label: 'More recipes',
url: `https://www.google.com/search?q=${RECIPE_NAME}+recipe`
url: `https://www.google.com/search?q=${RECIPE_NAME}+recipe`,
},
{
label: 'Yelp (takeout pls)',
url: `https://www.yelp.com/search?find_loc=${yelpLocation}&find_desc=${RECIPE_NAME}`
}
url: `https://www.yelp.com/search?find_loc=${yelpLocation}&find_desc=${RECIPE_NAME}`,
},
],

/**
Expand Down
Loading

0 comments on commit 22695ad

Please sign in to comment.