@@ -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 ( / d a t e : \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
4162const extractUrls = ( content ) => {
4263 const urlRegex = / h t t p s ? : \/ \/ [ ^ \s \) ] + / g;
@@ -78,9 +99,20 @@ const validateTimestamps = (content) => {
7899const 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