Skip to content

Commit 66b3dab

Browse files
w3cjcursoragent
andauthored
Fix/skip megaphone validation unpublished episodes (#2079)
* feat: Skip megaphone.fm validation for unpublished episodes Co-authored-by: cj.reynolds <cj.reynolds@sentry.io> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent b3f7166 commit 66b3dab

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

scripts/merging-show-validation.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ async function isUrlValid(url, method = 'HEAD') {
3737
}
3838
}
3939

40+
// Function to parse front-matter and get the episode date
41+
const getEpisodeDate = (content) => {
42+
const frontMatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
43+
if (!frontMatterMatch) return null;
44+
45+
const frontMatter = frontMatterMatch[1];
46+
const dateMatch = frontMatter.match(/date:\s*(\d+)/);
47+
if (!dateMatch) return null;
48+
49+
return parseInt(dateMatch[1], 10);
50+
};
51+
52+
// Function to check if episode is published
53+
const isEpisodePublished = (content) => {
54+
const episodeDate = getEpisodeDate(content);
55+
if (!episodeDate) return true; // If we can't find a date, assume it's published to be safe
56+
57+
const now = Date.now();
58+
return episodeDate <= now;
59+
};
60+
4061
// Function to extract URLs from markdown content
4162
const extractUrls = (content) => {
4263
const urlRegex = /https?:\/\/[^\s\)]+/g;
@@ -78,9 +99,20 @@ const validateTimestamps = (content) => {
7899
const processFile = async (filePath) => {
79100
const content = await fs.readFile(filePath, 'utf8');
80101
const urls = extractUrls(content);
81-
const checkPromises = urls.map(isUrlValid);
102+
const published = isEpisodePublished(content);
103+
104+
// Filter URLs to check - skip traffic.megaphone.fm for unpublished episodes
105+
const urlsToCheck = urls.filter((url) => {
106+
if (!published && url.includes('traffic.megaphone.fm')) {
107+
console.log(`Skipping validation for unpublished episode URL: ${url}`);
108+
return false;
109+
}
110+
return true;
111+
});
112+
113+
const checkPromises = urlsToCheck.map(isUrlValid);
82114
const results = await Promise.all(checkPromises);
83-
const brokenLinks = urls.filter((_, index) => !results[index]);
115+
const brokenLinks = urlsToCheck.filter((_, index) => !results[index]);
84116

85117
const invalidTimestamps = validateTimestamps(content);
86118

0 commit comments

Comments
 (0)