Skip to content

Commit 46dee93

Browse files
authored
Fix(config): allowing aligning Pug indentation with the current one (#265)
* fix: allow aligning Pug indentation with the current one * fix: minor change
1 parent 2decdaa commit 46dee93

File tree

2 files changed

+77
-49
lines changed

2 files changed

+77
-49
lines changed

config/esbuild/plugins/pugPlugin.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,29 @@ const pugPlugin = {
1919
// Transform all pug templates to HTML
2020
contents = contents.replace(pugTemplateRegex, (match, pugCode) => {
2121
try {
22-
// Manage interpolations ${...} in the template
22+
// Handle indentation
23+
const lines = pugCode.split('\n');
24+
if (lines.length > 1) {
25+
// Find the common indentation
26+
const indentMatch = lines[1].match(/^\s+/);
27+
if (indentMatch) {
28+
const baseIndent = indentMatch[0];
29+
// Remove the common indentation from all lines
30+
pugCode = lines
31+
.map((line, index) => {
32+
// Skip the first empty line if it exists
33+
if (index === 0 && line.trim() === '') return '';
34+
// Remove base indentation only if line starts with it
35+
if (line.startsWith(baseIndent)) {
36+
return line.slice(baseIndent.length);
37+
}
38+
return line;
39+
})
40+
.join('\n');
41+
}
42+
}
43+
44+
// Handle interpolations
2345
const interpolationPlaceholders = [];
2446
let index = 0;
2547

@@ -46,11 +68,17 @@ const pugPlugin = {
4668
);
4769
});
4870

49-
// Return the literal template with the compiled HTML
71+
// Clean up extra whitespace and newlines
72+
html = html
73+
.split('\n')
74+
.map(line => line.trimRight())
75+
.join('\n')
76+
.trim();
77+
5078
return 'html`' + html.replace(/`/g, '\\`') + '`';
5179
} catch (error) {
5280
console.error('Error compiling Pug template:', error);
53-
return match; // In case of error, keep the original template
81+
throw error; // Rethrow the error to stop the build
5482
}
5583
});
5684

src/features/optionsPage/ExportOptions.ts

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -70,52 +70,52 @@ export class ExportOptions extends LitElement {
7070
/* language=pug */
7171
render() {
7272
return pug`
73-
main.container
74-
.title-div
75-
span.inner-span-image(style="margin-right: 10px;")
76-
img(
77-
src="${chrome.runtime.getURL('../files/icons/icon-48.png')}"
78-
alt="${appInfos.APP_SNAME} icon"
79-
width="48"
80-
height="48"
81-
)
82-
h1.title Export Options
83-
form#options-form(@submit="${this.saveOptions}")
84-
#options-fieldset
85-
sl-input#filenameTemplate(
86-
.value="${this.filenameTemplate}"
87-
@sl-input="${this.handleInputChange}"
88-
placeholder="Enter filename format"
89-
label="Filename format:"
90-
)
91-
div
92-
p The filename format is a string containing placeholders, that will be replaced by the actual values when exporting a page.
93-
p The currently supported placeholders are:
94-
i Domain placeholders:
95-
ul
96-
li %W - Sub-domain name (e.g. "Phind Search", "Perplexity Pages")
97-
li %H - Host name (e.g. "www.chatgpt.com")
98-
li %T - Title of the page (first 60 characters)
99-
i Date placeholders:
100-
ul
101-
li %t - Timestamp (Unix time)
102-
li %Y - Year
103-
li %M - Month
104-
li %D - Day
105-
li %h - Hour
106-
li %m - Minutes
107-
li %s - Seconds
108-
sl-input#webhookUrl(
109-
.value="${this.webhookUrl}"
110-
@sl-input="${this.handleInputChange}"
111-
placeholder="Enter webhook URL (optional)"
112-
label="Webhook URL:"
113-
)
114-
sl-button(variant="primary" type="submit") Save changes
115-
p(class="feedback")
116-
span Options page is currently in beta.
117-
a(href="${appInfos.URLS.DISCUSSIONS}" target="_blank") Share feedback and report bugs.
118-
div(class="toast-stack")
73+
main.container
74+
.title-div
75+
span.inner-span-image(style="margin-right: 10px;")
76+
img(
77+
src="${chrome.runtime.getURL('../files/icons/icon-48.png')}"
78+
alt="${appInfos.APP_SNAME} icon"
79+
width="48"
80+
height="48"
81+
)
82+
h1.title Export Options
83+
form#options-form(@submit="${this.saveOptions}")
84+
#options-fieldset
85+
sl-input#filenameTemplate(
86+
.value="${this.filenameTemplate}"
87+
@sl-input="${this.handleInputChange}"
88+
placeholder="Enter filename format"
89+
label="Filename format:"
90+
)
91+
div
92+
p The filename format is a string containing placeholders, that will be replaced by the actual values when exporting a page.
93+
p The currently supported placeholders are:
94+
i Domain placeholders:
95+
ul
96+
li %W - Sub-domain name (e.g. "Phind Search", "Perplexity Pages")
97+
li %H - Host name (e.g. "www.chatgpt.com")
98+
li %T - Title of the page (first 60 characters)
99+
i Date placeholders:
100+
ul
101+
li %t - Timestamp (Unix time)
102+
li %Y - Year
103+
li %M - Month
104+
li %D - Day
105+
li %h - Hour
106+
li %m - Minutes
107+
li %s - Seconds
108+
sl-input#webhookUrl(
109+
.value="${this.webhookUrl}"
110+
@sl-input="${this.handleInputChange}"
111+
placeholder="Enter webhook URL (optional)"
112+
label="Webhook URL:"
113+
)
114+
sl-button(variant="primary" type="submit") Save changes
115+
p(class="feedback")
116+
span Options page is currently in beta.
117+
a(href="${appInfos.URLS.DISCUSSIONS}" target="_blank") Share feedback and report bugs.
118+
div(class="toast-stack")
119119
`;
120120
}
121121

0 commit comments

Comments
 (0)