Create or Update Open Graph Data
Goal:
To start a build orchestrator from scrach as simple as possible, with no overly zealous validations, error corrections, or even error handlig.
Before we proceed, read the Constraints instructions.
site/src/content/lost-in-public/prompting/Meticulous-Constraints-for-Every-Prompt.mdNow, we are working from the
site/scripts/build-scripts/simpleBuildOrchestrator.cjs file.The goal is to successfully process files that meet a certain condition set by the user with the
site/scripts/build-scripts/fetchOpenGraphData.cjs file.We will also need to write a utility function that should be abstracted and versatile and handle exceptions and errors gracefully. We will write that in the
site/scripts/build-scripts/utils/processFilesForTargetScript.cjs file.The
simpleBuildOrchestrator.cjs file should be the centerpiece. We stay DRY (Don't Repeat Yourself) and use the functions from the files above. We keep a single source of truth.- From the
simpleBuildOrchestrator.cjsfile, Create a USER_OPTIONS object with aTARGET_DIRproperty set to the directory containing the markdown files. aREPORT_FILEproperty set to the file where the report will be written. aDAYS_SINCE_LAST_API_CALLproperty set to the number of days since the last API call. - From the
utils/processFilesForTargetScript.cjsfile, Create a dead simple but versatileloadFilesfunction that will gather all the markdown files recursively in theTARGET_DIRinto an array of paths.We cannot use glob or grayMatter or any other libraries that process YAML or Markdown. We must use plain text or strings.- The
loadFilesfunction must be able to receive theTARGET_DIRproperty from theUSER_OPTIONSobject.
- This
targetMarkdownFilesArraywill then move to afilterFilesArrayByConditionfunction that will filter the files based on theDAYS_SINCE_LAST_API_CALLproperty from theUSER_OPTIONSobject, which must be passed as a parameter from theUSER_OPTIONSobject in thesimpleBuildOrchestrator.cjsfile. - The conditions for running the
fetchOpenGraphDatafunction are: If no og_last_fetch is present in frontmatter, or if the og_last_fetch property has no value, or if it has been longer than 30 days since the last API call, then run the importedfetchOpenGraphDatafunction. These should be set in theRUN_CONDITIONSproperty of theUSER_OPTIONSobject in thesimpleBuildOrchestrator.cjsfile. - You may review the
fetchOpenGraphDatafunction in theutils/fetchOpenGraphData.cjsfile and make suggestions for dramatic refactoring. The last attempts at runningpnpm buildended up corrupting a whole bunch of files. - The
processFilesForTargetScriptwill need to send the proper parameters to thefetchOpenGraphDatafunction. Diagnose what those may be. - The
fetchOpenGraphDatafunction should return a promise that resolves to an object that is already defined in thefetchOpenGraphData.cjsfile. - Already in the
fetchOpenGraphData.cjsfile should be how to handle API call errors, or error response objects. - The missing piece in
fetchOpenGraphData.cjsshould be- How to do reporting consistent with our
getReportingFormatForBuild.cjsfile and use thesingleOperationReportTemplatetemplate. - How to create a record in the JSON document related to the success or error from the API Call into the
site/src/content/data/markdown-content-registry.jsonfile in. It should add to the metadata section of the json object connected to the file by thesite_uuidproeprty.