Skip to content

Commit

Permalink
feat: allow path/**/* usage for images src (#118)
Browse files Browse the repository at this point in the history
* feat: add markdown content route config

- update index.spec.js

- reduce markdown input to bare minimum

address #61

* refactor: remove commented code

* docs: update plugin markdown docs

* feat: allow path/**/* usage for images src

- fix manifest not found when using **/*

close #67

* docs: update plugin-images docs

* fix(image-plugin): include plugin config

- resolves #119
  • Loading branch information
noxasch committed Jul 30, 2021
1 parent bf303c1 commit a2e2688
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ plugins: {
folders: [
{
src: '/images/*', // glob of where your original images are. Relative to rootDir/process.cwd() defined in your elder.config.js. Careful with **.
// src: 'articles/**/*' is also acceptable
output: '/images/', // where files should be put within the distDir defined in your elder.config.js.
},
],
Expand Down
10 changes: 6 additions & 4 deletions packages/images/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const processImages = async ({
images = [],
widths = defaultWidths,
scales = defaultScales,
plugin = {},
s3,
debug,
}) => {
Expand Down Expand Up @@ -286,15 +287,15 @@ const plugin = {
plugin.crossPlatformRoot = plugin.settings.rootDir.replace(/\\/gim, '/');

const imagesToProcess = folders.reduce((out, folder) => {
const relGlob = folder.src.replace('.', '').replace(/\*/g, '');

fs.ensureDirSync(path.join(plugin.settings.distDir, folder.output));
const files = glob.sync(path.join(plugin.settings.rootDir, folder.src));
const files = glob.sync(path.join(plugin.settings.rootDir, folder.src + `.{${imageFileTypes.join(',')}}`));
if (Array.isArray(files)) {
files
.filter((file) => imageFileTypes.includes(file.split('.').pop().toLowerCase()))
.filter((file) => !file.split('/').pop().includes('-ejs'))
.forEach((file) => {
// fix manifest not found and wrong output folder when using **/*
const relGlob = file.replace(plugin.settings.rootDir, '').replace(file.split('/').pop(), '');

const crossPlatformFile = file.replace(plugin.crossPlatformRoot, '');

const name = crossPlatformFile.replace(relGlob, '');
Expand Down Expand Up @@ -364,6 +365,7 @@ const plugin = {
images: plugin.imagesToProcess,
widths,
scales,
plugin,
s3: plugin.config.s3,
debug: plugin.config.debug,
});
Expand Down

0 comments on commit a2e2688

Please sign in to comment.