Skip to content

Commit

Permalink
Merge pull request #641 from shawnthompson/list-page-update
Browse files Browse the repository at this point in the history
List page update
  • Loading branch information
shawnthompson authored Sep 13, 2024
2 parents 95875f7 + c8887c4 commit 871e11d
Showing 1 changed file with 59 additions and 14 deletions.
73 changes: 59 additions & 14 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const changedPageUrls = [];

// ANSI escape codes for blue underline
const underline = '\x1b[4m'; // Underline font
const resetColor = '\x1b[0m'; // Reset font to default
const resetColor = '\x1b[0m'; // Reset font to default

// Check if we are in watch mode (development)
const isWatchMode = process.env.ELEVENTY_WATCH === 'true';

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

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

gitChangedFiles.forEach((file) => {
// Check if the file is contained within the 'src/main' or 'src/pages' directories
// and is an .md or .njk file
if ((file.startsWith('src/main/') || file.startsWith('src/pages/')) && (file.endsWith('.md') || file.endsWith('.njk'))) {
if ((file.startsWith('src/main/') || file.startsWith('src/pages/')) &&
(file.endsWith('.md') || file.endsWith('.njk'))) {
// Track the file
changedFilePaths.add(file);
}
});

// Clean up: delete the upstream-main branch after the diff
try {
execSync('git branch -D upstream-main');
} catch (err) {
console.error('Error deleting the upstream-main branch', err);
}
});

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

// Check if this file was changed based on Git diff
if (changedFilePaths.has(inputPath)) {
const fullUrl = `${domain}:${port}${this.page.url}`;

// Log the URL in blue and underlined
console.log(`${underline}Captured URL: ${fullUrl}${resetColor}`);

gitChangedUrls.push(fullUrl); // Store the URL to log later
// Adjust URL generation to prevent double port addition
let fullUrl = domain;

// Only add the port if it's localhost and it hasn't been added already
if (domain.includes('localhost') && !domain.includes(`:${port}`)) {
fullUrl += `:${port}`;
}

// Append the page URL
fullUrl += this.page.url;

if (isWatchMode) {
// Log individual URLs for each changed page in dev mode
console.log(`${underline}Captured URL: ${fullUrl}${resetColor}`);
} else {
// Log file paths in production mode
console.log(`${underline}Changed file: ${inputPath}${resetColor}`);
}

// Track the URL or file path for summary logging later
gitChangedUrls.push(isWatchMode ? fullUrl : inputPath);
}
}
return content;
});

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

if (changedFilesCount > 0) {
// Log summary and provide the correct link based on the environment
// Log the summary of changed pages
console.log(`\n${changedFilesCount} page(s) changed.`);
console.log(`Review the changed pages here: ${underline}${domain}/en/pages-to-review/${resetColor}\n`);

// Log individual URLs or file paths, depending on mode
gitChangedUrls.forEach((changedItem) => {
console.log(`${underline}${changedItem}${resetColor}`);
});

// Add a blank line after the list of changed pages
console.log('');

// Only log the review page link in local development mode
if (isWatchMode) {
let reviewPageLink = `${domain}`;
if (domain.includes('localhost') && !domain.includes(`:${port}`)) {
reviewPageLink += `:${port}`;
}
reviewPageLink += '/en/pages-to-review/';

console.log(`\nReview the changed pages here: ${underline}${reviewPageLink}${resetColor}\n`);
}
} else {
console.log('No pages to review.\n');
}

changedFilePaths.clear(); // Clear the set for the next watch cycle
// Clear the set for the next watch cycle
changedFilePaths.clear();
gitChangedUrls = [];
});

return {
Expand Down

0 comments on commit 871e11d

Please sign in to comment.