Skip to content

Commit

Permalink
Refactor imageBase to assetBaseUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
tennox committed Nov 7, 2022
1 parent 2ae553b commit d107666
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ __`--out`__: Replaces the default output directory (`./output`) with the one pro

A `config.js` file exists to provide configuration parameters for the build. The following attribute is supported:

- **`imageBase`**: The absolute URL where images are to be accessible publicly.
- **`assetBaseUrl`**: The absolute URL where images are to be accessible publicly.


## About images
Expand All @@ -71,7 +71,7 @@ This would refer to an image stored in the following directory: `src/assets/logo

It is not part of the scope of this tool to sync or upload images to a public hosting environment. All the tool does is repatriate every image file under the `src/assets` directory into the `output/assets` directory when building the project. Those files should then be uploaded/synced to a Web server serving static files.

When building templates for production (see _Building for production_ below), the `$IMGBASE$` variables will be replaced by the `imageBase` configuration attribute in `config.js`.
When building templates for production (see _Building for production_ below), the `$IMGBASE$` variables will be replaced by the `assetBaseUrl` configuration attribute in `config.js`.

## About translations / i18n

Expand Down
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
// This is where your images are to be hosted publicly - e.g. 'https://domain.org/images'
imageBase: process.env.EMAIL_ASSET_URL,
assetBaseUrl: process.env.EMAIL_ASSET_URL,
};
8 changes: 4 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const production = environments.production;

const mjmlEngine = require('mjml');

let imageBase = production() ? config.imageBase : './assets';
if (!imageBase) throw new Error(`Empty imageBase in config.js`)
if (imageBase.endsWith('/')) imageBase = imageBase.replace(/\/$/, "") // remove trailing slash
let assetBaseUrl = production() ? config.assetBaseUrl : './assets';
if (!assetBaseUrl) throw new Error(`Empty assetBaseUrl in config.js`)
if (assetBaseUrl.endsWith('/')) assetBaseUrl = assetBaseUrl.replace(/\/$/, "") // remove trailing slash

const argOutput = argv.out || './output';

Expand Down Expand Up @@ -52,7 +52,7 @@ gulp.task('copy:assets', function () {
gulp.task('build:html', function () {
return gulp.src(files.templates)
.pipe(nunjucks.compile({
assetBaseUrl: imageBase
assetBaseUrl
}, { searchPath: dirs.templates }))
.pipe(mjml(mjmlEngine, {
minify: false,
Expand Down

0 comments on commit d107666

Please sign in to comment.