@maizzle/framework 5.0.1 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/build.js +2 -2
- package/src/generators/plaintext.js +2 -2
- package/src/posthtml/plugins/envAttributes.js +1 -1
- package/src/posthtml/plugins/envTags.js +1 -1
- package/src/posthtml/plugins/expandLinkTag.js +3 -2
- package/src/transformers/baseUrl.js +50 -3
- package/types/index.d.ts +16 -4
package/package.json
CHANGED
package/src/commands/build.js
CHANGED
|
@@ -107,7 +107,7 @@ export default async (config = {}) => {
|
|
|
107
107
|
/**
|
|
108
108
|
* Check that templates to be built, actually exist
|
|
109
109
|
*/
|
|
110
|
-
const contentPaths = get(config, 'build.content', ['
|
|
110
|
+
const contentPaths = get(config, 'build.content', ['emails/**/*.html'])
|
|
111
111
|
|
|
112
112
|
const templateFolders = Array.isArray(contentPaths) ? contentPaths : [contentPaths]
|
|
113
113
|
const templatePaths = await fg.glob([...new Set(templateFolders)])
|
|
@@ -122,7 +122,7 @@ export default async (config = {}) => {
|
|
|
122
122
|
*
|
|
123
123
|
* Copies each `build.content` path to the `build.output.path` directory.
|
|
124
124
|
*/
|
|
125
|
-
let from = get(config, 'build.output.from', ['
|
|
125
|
+
let from = get(config, 'build.output.from', ['emails'])
|
|
126
126
|
|
|
127
127
|
const globPathsToCopy = contentPaths.map(glob => {
|
|
128
128
|
// Keep negated paths as they are
|
|
@@ -150,7 +150,7 @@ export async function writePlaintextFile(plaintext = '', config = {}) {
|
|
|
150
150
|
* `config.build.output.path`
|
|
151
151
|
*/
|
|
152
152
|
const plaintextConfig = get(config, 'plaintext')
|
|
153
|
-
let plaintextOutputPath = get(plaintextConfig, 'output.path',
|
|
153
|
+
let plaintextOutputPath = get(plaintextConfig, 'output.path', '')
|
|
154
154
|
const plaintextExtension = get(plaintextConfig, 'output.extension', 'txt')
|
|
155
155
|
|
|
156
156
|
/**
|
|
@@ -158,7 +158,7 @@ export async function writePlaintextFile(plaintext = '', config = {}) {
|
|
|
158
158
|
* output plaintext file in the same location as the HTML file.
|
|
159
159
|
*/
|
|
160
160
|
if (plaintextConfig === true) {
|
|
161
|
-
plaintextOutputPath =
|
|
161
|
+
plaintextOutputPath = ''
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
/**
|
|
@@ -8,7 +8,7 @@ const plugin = (() => tree => {
|
|
|
8
8
|
/**
|
|
9
9
|
* Don't expand link tags that are not explicitly marked as such
|
|
10
10
|
*/
|
|
11
|
-
if (node
|
|
11
|
+
if (node?.attrs && ![...targets].some(attr => attr in node.attrs)) {
|
|
12
12
|
for (const attr of targets) {
|
|
13
13
|
node.attrs[attr] = false
|
|
14
14
|
}
|
|
@@ -17,7 +17,8 @@ const plugin = (() => tree => {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
if (
|
|
20
|
-
node
|
|
20
|
+
node
|
|
21
|
+
&& node.tag === 'link'
|
|
21
22
|
&& node.attrs
|
|
22
23
|
&& node.attrs.href
|
|
23
24
|
&& node.attrs.rel === 'stylesheet'
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
2
|
import isUrl from 'is-url-superb'
|
|
3
3
|
import get from 'lodash-es/get.js'
|
|
4
|
-
import baseUrl from 'posthtml-base-url'
|
|
5
4
|
import { render } from 'posthtml-render'
|
|
6
5
|
import isEmpty from 'lodash-es/isEmpty.js'
|
|
7
6
|
import isObject from 'lodash-es/isObject.js'
|
|
8
7
|
import { parser as parse } from 'posthtml-parser'
|
|
9
8
|
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
9
|
+
import baseUrl, { parseSrcset, stringifySrcset, defaultTags } from 'posthtml-base-url'
|
|
10
10
|
|
|
11
11
|
const posthtmlOptions = getPosthtmlOptions()
|
|
12
12
|
|
|
@@ -48,11 +48,11 @@ const posthtmlPlugin = url => tree => {
|
|
|
48
48
|
|
|
49
49
|
export default posthtmlPlugin
|
|
50
50
|
|
|
51
|
-
export async function addBaseUrl(html = '', options = {},
|
|
51
|
+
export async function addBaseUrl(html = '', options = {}, posthtmlOpts = {}) {
|
|
52
52
|
return posthtml([
|
|
53
53
|
posthtmlPlugin(options)
|
|
54
54
|
])
|
|
55
|
-
.process(html, getPosthtmlOptions())
|
|
55
|
+
.process(html, getPosthtmlOptions(posthtmlOpts))
|
|
56
56
|
.then(result => result.html)
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -99,5 +99,52 @@ const rewriteVMLs = (html, url) => {
|
|
|
99
99
|
})
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Handle other sources inside MSO comments
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
// Make a | pipe-separated list of all the default tags and use it to create a regex
|
|
107
|
+
const uniqueSourceAttributes = [
|
|
108
|
+
...new Set(Object.values(defaultTags).flatMap(Object.keys))
|
|
109
|
+
].join('|')
|
|
110
|
+
|
|
111
|
+
const sourceAttrRegex = new RegExp(`\\b(${uniqueSourceAttributes})="([^"]+)"`, 'g')
|
|
112
|
+
|
|
113
|
+
// Replace all the source attributes inside MSO comments
|
|
114
|
+
html = html.replace(/<!--\[if [^\]]+\]>[\s\S]*?<!\[endif\]-->/g, (msoBlock) => {
|
|
115
|
+
return msoBlock.replace(sourceAttrRegex, (match, attr, value) => {
|
|
116
|
+
if (isUrl(value)) {
|
|
117
|
+
return match
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const updatedValue = attr === 'srcset'
|
|
121
|
+
? processSrcset(value, url)
|
|
122
|
+
: url + value
|
|
123
|
+
|
|
124
|
+
return `${attr}="${updatedValue}"`
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
|
|
102
128
|
return html
|
|
103
129
|
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Add the base URL to the srcset URLs
|
|
133
|
+
*
|
|
134
|
+
* @param {*} srcsetValue The value of the srcset attribute
|
|
135
|
+
* @param {*} url The base URL
|
|
136
|
+
* @returns {string} The updated srcset attribute value
|
|
137
|
+
*/
|
|
138
|
+
function processSrcset(srcsetValue, url) {
|
|
139
|
+
const parsed = parseSrcset(srcsetValue)
|
|
140
|
+
|
|
141
|
+
parsed.map(p => {
|
|
142
|
+
if (!isUrl(p.url)) {
|
|
143
|
+
p.url = url + p.url
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return p
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
return stringifySrcset(parsed)
|
|
150
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type CSSInlineConfig from './css/inline';
|
|
|
9
9
|
import type WidowWordsConfig from './widowWords';
|
|
10
10
|
import type { BaseURLConfig } from 'posthtml-base-url';
|
|
11
11
|
import type { HTMLBeautifyOptions } from 'js-beautify'
|
|
12
|
+
import type { Opts as PlaintextOptions } from 'string-strip-html';
|
|
12
13
|
import type { URLParametersConfig } from 'posthtml-url-parameters';
|
|
13
14
|
import type { AttributeToStyleSupportedAttributes } from './css/inline';
|
|
14
15
|
|
|
@@ -188,11 +189,22 @@ declare namespace MaizzleFramework {
|
|
|
188
189
|
/**
|
|
189
190
|
* Generate a plaintext version of an HTML string.
|
|
190
191
|
* @param {string} html - The HTML string to convert to plaintext.
|
|
191
|
-
* @param {
|
|
192
|
-
* @
|
|
192
|
+
* @param {Object} [config={}] - Configuration object.
|
|
193
|
+
* @param {PostHTMLConfig} [config.posthtml] - PostHTML options.
|
|
194
|
+
* @param {PlaintextOptions} [config.strip] - Options for `string-strip-html`.
|
|
195
|
+
* @returns {Promise<string>} A string representing the HTML converted to plaintext.
|
|
193
196
|
* @see https://maizzle.com/docs/plaintext
|
|
194
197
|
*/
|
|
195
|
-
function
|
|
198
|
+
function generatePlaintext(
|
|
199
|
+
html: string,
|
|
200
|
+
config?: {
|
|
201
|
+
/**
|
|
202
|
+
* Configure PostHTML options.
|
|
203
|
+
*/
|
|
204
|
+
posthtml?: PostHTMLConfig
|
|
205
|
+
}
|
|
206
|
+
& PlaintextOptions,
|
|
207
|
+
): Promise<string>;
|
|
196
208
|
|
|
197
209
|
export {
|
|
198
210
|
Config,
|
|
@@ -213,7 +225,7 @@ declare namespace MaizzleFramework {
|
|
|
213
225
|
sixHEX,
|
|
214
226
|
minify,
|
|
215
227
|
replaceStrings,
|
|
216
|
-
|
|
228
|
+
generatePlaintext,
|
|
217
229
|
}
|
|
218
230
|
}
|
|
219
231
|
|