diff --git a/src/automated-pipelines/lib/update-markdown.js b/src/automated-pipelines/lib/update-markdown.js index b10c6cf449..72d42348b0 100644 --- a/src/automated-pipelines/lib/update-markdown.js +++ b/src/automated-pipelines/lib/update-markdown.js @@ -11,8 +11,7 @@ import { allVersions } from '../../../lib/all-versions.js' import getApplicableVersions from '../../../lib/get-applicable-versions.js' const ROOT_INDEX_FILE = 'content/index.md' -export const MARKDOWN_COMMENT = - '\n\n\n\n' +export const MARKDOWN_COMMENT = '\n\n' // Main entrypoint into this module. This function adds, removes, and updates // versions frontmatter in all directories under the targetDirectory. @@ -100,11 +99,15 @@ async function updateMarkdownFile( throw new Error(`Error: ${file} has multiple comment delimiters`) } - // Only proceed if the content or versions have changed - const [manuallyCreatedContent, automatedContent] = content.split(commentDelimiter) + const [manuallyCreatedContent, automatedContent] = matches + ? content.split(commentDelimiter) + : [content, ''] + + const isDelimiterMissing = !matches const isContentSame = automatedContent === sourceContent const isVersionsSame = isEqual(sourceData.versions, data.versions) - if (isContentSame && isVersionsSame) { + // Only proceed if the content or versions have changed + if (isContentSame && isVersionsSame && !isDelimiterMissing) { return } @@ -116,7 +119,7 @@ async function updateMarkdownFile( await writeFile(file, matter.stringify(targetContent, newData)) } else { await createDirectory(path.dirname(file)) - await writeFile(file, matter.stringify(sourceContent, sourceData)) + await writeFile(file, matter.stringify(commentDelimiter + sourceContent, sourceData)) } } diff --git a/src/codeql-cli/scripts/sync.js b/src/codeql-cli/scripts/sync.js index 6528ec1dfd..8900fb1e38 100755 --- a/src/codeql-cli/scripts/sync.js +++ b/src/codeql-cli/scripts/sync.js @@ -17,7 +17,7 @@ const { targetDirectory, sourceDirectory, frontmatterDefaults, markdownPrefix } ) const SOURCE_REPO = sourceDirectory.split('/')[0] const TEMP_DIRECTORY = path.join(SOURCE_REPO, 'tempCliDocs') -const MARKDOWN_PREFIX = `${markdownPrefix}\n\n` +const MARKDOWN_PREFIX = `\n${markdownPrefix}\n\n` main() diff --git a/src/rest/scripts/utils/update-markdown.js b/src/rest/scripts/utils/update-markdown.js index 923d48e1b8..b790e236ce 100644 --- a/src/rest/scripts/utils/update-markdown.js +++ b/src/rest/scripts/utils/update-markdown.js @@ -5,7 +5,6 @@ import { readFile } from 'fs/promises' import { updateContentDirectory, convertVersionsToFrontmatter, - MARKDOWN_COMMENT, } from '../../../automated-pipelines/lib/update-markdown.js' import { getDocsVersion } from '../../../../lib/all-versions.js' import { REST_DATA_DIR, REST_SCHEMA_FILENAME } from '../../lib/index.js' @@ -102,7 +101,7 @@ async function getMarkdownContent(versions) { ), ...frontmatterDefaults, }, - content: MARKDOWN_COMMENT, + content: '', } continue } @@ -118,7 +117,7 @@ async function getMarkdownContent(versions) { versions: await convertVersionsToFrontmatter(versions[category][subcategory].versions), ...frontmatterDefaults, }, - content: MARKDOWN_COMMENT, + content: '', } } }