@@ -36,6 +36,16 @@ async function writePosts(posts) {
3636 await fs . writeFile ( POSTS_JSON , JSON . stringify ( posts , null , 2 ) , 'utf-8' ) ;
3737}
3838
39+ function getYoutubeEmbedUrl ( url ) {
40+ if ( ! url ) return null ;
41+ const regExp = / ^ .* ( y o u t u .b e \/ | v \/ | u \/ \w \/ | e m b e d \/ | w a t c h \? v = | & v = ) ( [ ^ # & ? ] * ) .* / ;
42+ const match = url . match ( regExp ) ;
43+ if ( match && match [ 2 ] . length === 11 ) {
44+ return `https://www.youtube.com/embed/${ match [ 2 ] } ` ;
45+ }
46+ return null ;
47+ }
48+
3949async function createPost ( args ) {
4050 const { title, slug, description, content, tags, category, image } = args ;
4151
@@ -84,15 +94,15 @@ async function createPost(args) {
8494}
8595
8696async function createDiscoveryLog ( args ) {
87- const { type, title, slug, rating, description, content, date, ...otherFields } = args ;
97+ const { type, title, slug, rating, description, content, date, link , image , ...otherFields } = args ;
8898
8999 // Validate slug
90100 if ( ! / ^ [ a - z 0 - 9 - ] + $ / . test ( slug ) ) {
91101 throw new Error ( 'Slug must contain only lowercase letters, numbers, and hyphens.' ) ;
92102 }
93103
94104 const typeLower = type . toLowerCase ( ) ;
95- const categoryDir = path . join ( LOGS_DIR , typeLower ) ;
105+ const categoryDir = path . resolve ( LOGS_DIR , typeLower ) ;
96106 const pimlPath = path . join ( categoryDir , `${ typeLower } .piml` ) ;
97107
98108 // Ensure directory exists
@@ -124,9 +134,11 @@ async function createDiscoveryLog(args) {
124134 const newItem = {
125135 category : type . charAt ( 0 ) . toUpperCase ( ) + type . slice ( 1 ) ,
126136 date : dateStr ,
137+ link : link || '' ,
127138 rating : parseInt ( rating , 10 ) ,
128139 slug,
129140 title,
141+ image : image || '' ,
130142 description,
131143 ...otherFields
132144 } ;
@@ -138,13 +150,21 @@ async function createDiscoveryLog(args) {
138150 const newPimlString = piml . stringify ( { logs } ) ;
139151 await fs . writeFile ( pimlPath , newPimlString , 'utf-8' ) ;
140152
141- // Create detailed content if provided
142- if ( content ) {
143- const txtPath = path . join ( categoryDir , `${ slug } .txt` ) ;
144- await fs . writeFile ( txtPath , content , 'utf-8' ) ;
153+ // Create detailed content (.txt)
154+ const txtPath = path . join ( categoryDir , `${ slug } .txt` ) ;
155+ let finalContent = content || description ;
156+
157+ const embedUrl = getYoutubeEmbedUrl ( link ) ;
158+ let txtBody = `# ${ title } \n\n` ;
159+ if ( embedUrl ) {
160+ txtBody += `<iframe width="100%" height="450" src="${ embedUrl } " title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>\n\n` ;
145161 }
162+ txtBody += `${ finalContent } \n\n` ;
163+ txtBody += `Rating: ${ rating } /5` ;
164+
165+ await fs . writeFile ( txtPath , txtBody , 'utf-8' ) ;
146166
147- return `Discovery log "${ title } " created successfully in ${ typeLower } .` ;
167+ return `Discovery log "${ title } " created successfully in ${ typeLower } with file ${ txtPath } .` ;
148168}
149169
150170// Server setup
0 commit comments