Skip to content

Commit 871e11d

Browse files
Merge pull request #641 from shawnthompson/list-page-update
List page update
2 parents 95875f7 + c8887c4 commit 871e11d

File tree

1 file changed

+59
-14
lines changed

1 file changed

+59
-14
lines changed

.eleventy.js

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ const changedPageUrls = [];
1313

1414
// ANSI escape codes for blue underline
1515
const underline = '\x1b[4m'; // Underline font
16-
const resetColor = '\x1b[0m'; // Reset font to default
16+
const resetColor = '\x1b[0m'; // Reset font to default
17+
18+
// Check if we are in watch mode (development)
19+
const isWatchMode = process.env.ELEVENTY_WATCH === 'true';
1720

1821
module.exports = function (eleventyConfig) {
1922
const eleventySlugify = eleventyConfig.getFilter('slug');
@@ -198,7 +201,7 @@ module.exports = function (eleventyConfig) {
198201
const upstreamUrl = 'https://github.com/gc-da11yn/gc-da11yn.github.io';
199202

200203
try {
201-
execSync(`git fetch ${upstreamUrl} main:upstream-main --depth=1`);
204+
execSync(`git fetch ${upstreamUrl} main:upstream-main --force --depth=1`);
202205
} catch (err) {
203206
console.error('Error fetching the upstream main branch', err);
204207
}
@@ -207,13 +210,19 @@ module.exports = function (eleventyConfig) {
207210
const gitChangedFiles = execSync('git diff upstream-main --name-only').toString().trim().split('\n');
208211

209212
gitChangedFiles.forEach((file) => {
210-
// Check if the file is contained within the 'src/main' or 'src/pages' directories
211-
// and is an .md or .njk file
212-
if ((file.startsWith('src/main/') || file.startsWith('src/pages/')) && (file.endsWith('.md') || file.endsWith('.njk'))) {
213+
if ((file.startsWith('src/main/') || file.startsWith('src/pages/')) &&
214+
(file.endsWith('.md') || file.endsWith('.njk'))) {
213215
// Track the file
214216
changedFilePaths.add(file);
215217
}
216218
});
219+
220+
// Clean up: delete the upstream-main branch after the diff
221+
try {
222+
execSync('git branch -D upstream-main');
223+
} catch (err) {
224+
console.error('Error deleting the upstream-main branch', err);
225+
}
217226
});
218227

219228
// Hook into the HTML generation process (logging to the console)
@@ -223,29 +232,65 @@ module.exports = function (eleventyConfig) {
223232

224233
// Check if this file was changed based on Git diff
225234
if (changedFilePaths.has(inputPath)) {
226-
const fullUrl = `${domain}:${port}${this.page.url}`;
227-
228-
// Log the URL in blue and underlined
229-
console.log(`${underline}Captured URL: ${fullUrl}${resetColor}`);
230-
231-
gitChangedUrls.push(fullUrl); // Store the URL to log later
235+
// Adjust URL generation to prevent double port addition
236+
let fullUrl = domain;
237+
238+
// Only add the port if it's localhost and it hasn't been added already
239+
if (domain.includes('localhost') && !domain.includes(`:${port}`)) {
240+
fullUrl += `:${port}`;
241+
}
242+
243+
// Append the page URL
244+
fullUrl += this.page.url;
245+
246+
if (isWatchMode) {
247+
// Log individual URLs for each changed page in dev mode
248+
console.log(`${underline}Captured URL: ${fullUrl}${resetColor}`);
249+
} else {
250+
// Log file paths in production mode
251+
console.log(`${underline}Changed file: ${inputPath}${resetColor}`);
252+
}
253+
254+
// Track the URL or file path for summary logging later
255+
gitChangedUrls.push(isWatchMode ? fullUrl : inputPath);
232256
}
233257
}
234258
return content;
235259
});
236260

261+
// After build, log a summary and provide a link to the review page in local development
237262
eleventyConfig.on('afterBuild', () => {
238263
const changedFilesCount = changedFilePaths.size;
239264

240265
if (changedFilesCount > 0) {
241-
// Log summary and provide the correct link based on the environment
266+
// Log the summary of changed pages
242267
console.log(`\n${changedFilesCount} page(s) changed.`);
243-
console.log(`Review the changed pages here: ${underline}${domain}/en/pages-to-review/${resetColor}\n`);
268+
269+
// Log individual URLs or file paths, depending on mode
270+
gitChangedUrls.forEach((changedItem) => {
271+
console.log(`${underline}${changedItem}${resetColor}`);
272+
});
273+
274+
// Add a blank line after the list of changed pages
275+
console.log('');
276+
277+
// Only log the review page link in local development mode
278+
if (isWatchMode) {
279+
let reviewPageLink = `${domain}`;
280+
if (domain.includes('localhost') && !domain.includes(`:${port}`)) {
281+
reviewPageLink += `:${port}`;
282+
}
283+
reviewPageLink += '/en/pages-to-review/';
284+
285+
console.log(`\nReview the changed pages here: ${underline}${reviewPageLink}${resetColor}\n`);
286+
}
244287
} else {
245288
console.log('No pages to review.\n');
246289
}
247290

248-
changedFilePaths.clear(); // Clear the set for the next watch cycle
291+
// Clear the set for the next watch cycle
292+
changedFilePaths.clear();
293+
gitChangedUrls = [];
249294
});
250295

251296
return {

0 commit comments

Comments
 (0)