| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | import { execSync } from "child_process"; | 
					
						
							| 
									
										
										
										
											2023-09-04 13:37:18 +09:00
										 |  |  | import matter from "gray-matter"; | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | import * as fs from "fs"; | 
					
						
							|  |  |  | import * as path from "path"; | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  | import { Octokit } from "@octokit/rest"; | 
					
						
							| 
									
										
										
										
											2021-07-08 15:17:51 -07:00
										 |  |  | import { throttling } from "@octokit/plugin-throttling"; | 
					
						
							|  |  |  | import { retry } from "@octokit/plugin-retry"; | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Note: this must be executed within the docs-website directory.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Constants.
 | 
					
						
							| 
									
										
										
										
											2025-04-28 23:34:33 +09:00
										 |  |  | const HOSTED_SITE_URL = "https://docs.datahub.com"; | 
					
						
							| 
									
										
										
										
											2022-03-18 22:12:19 +01:00
										 |  |  | const GITHUB_EDIT_URL = | 
					
						
							|  |  |  |   "https://github.com/datahub-project/datahub/blob/master"; | 
					
						
							|  |  |  | const GITHUB_BROWSE_URL = | 
					
						
							|  |  |  |   "https://github.com/datahub-project/datahub/blob/master"; | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-29 00:52:16 -05:00
										 |  |  | const OUTPUT_DIRECTORY = "docs"; | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-07 10:46:27 -08:00
										 |  |  | const SIDEBARS_DEF_PATH = "./sidebars.js"; | 
					
						
							|  |  |  | const sidebars = require(SIDEBARS_DEF_PATH); | 
					
						
							| 
									
										
										
										
											2021-03-08 15:39:49 -08:00
										 |  |  | const sidebars_json = JSON.stringify(sidebars); | 
					
						
							|  |  |  | const sidebars_text = fs.readFileSync(SIDEBARS_DEF_PATH).toString(); | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-08 15:17:51 -07:00
										 |  |  | const MyOctokit = Octokit.plugin(retry).plugin(throttling); | 
					
						
							|  |  |  | const octokit = new MyOctokit({ | 
					
						
							|  |  |  |   throttle: { | 
					
						
							| 
									
										
										
										
											2023-09-04 13:37:18 +09:00
										 |  |  |     onRateLimit: (retryAfter: number, options: any) => { | 
					
						
							| 
									
										
										
										
											2021-07-08 15:17:51 -07:00
										 |  |  |       // Retry twice after rate limit is hit.
 | 
					
						
							|  |  |  |       if (options.request.retryCount <= 2) { | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     onAbuseLimit: () => { | 
					
						
							|  |  |  |       console.warn("GitHub API hit abuse limit"); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-03-07 10:46:27 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function actually_in_sidebar(filepath: string): boolean { | 
					
						
							| 
									
										
										
										
											2021-03-08 15:39:49 -08:00
										 |  |  |   const doc_id = get_id(filepath); | 
					
						
							|  |  |  |   return sidebars_json.indexOf(`"${doc_id}"`) >= 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function accounted_for_in_sidebar(filepath: string): boolean { | 
					
						
							|  |  |  |   if (actually_in_sidebar(filepath)) { | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // If we want to explicitly not include a doc in the sidebar but still have it
 | 
					
						
							|  |  |  |   // available via a direct link, then keeping it commented out in the sidebar
 | 
					
						
							|  |  |  |   // serves this purpose. To make it work, we search the text of the sidebar JS
 | 
					
						
							|  |  |  |   // file.
 | 
					
						
							|  |  |  |   const doc_id = get_id(filepath); | 
					
						
							|  |  |  |   if (sidebars_text.indexOf(`"${doc_id}"`) >= 0) { | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2021-03-07 10:46:27 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | function list_markdown_files(): string[] { | 
					
						
							| 
									
										
										
										
											2022-02-17 15:15:39 -05:00
										 |  |  |   let all_markdown_files = execSync("git ls-files --full-name .. | grep '.md$'") | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |     .toString() | 
					
						
							|  |  |  |     .trim() | 
					
						
							|  |  |  |     .split("\n"); | 
					
						
							| 
									
										
										
										
											2022-02-18 09:45:45 -08:00
										 |  |  |   let all_generated_markdown_files = execSync( | 
					
						
							| 
									
										
										
										
											2023-10-04 17:43:59 +09:00
										 |  |  |     "cd .. && ls docs/generated/**/**/*.md && ls docs/generated/**/*.md" | 
					
						
							| 
									
										
										
										
											2022-02-18 09:45:45 -08:00
										 |  |  |   ) | 
					
						
							|  |  |  |     .toString() | 
					
						
							|  |  |  |     .trim() | 
					
						
							|  |  |  |     .split("\n"); | 
					
						
							| 
									
										
										
										
											2022-03-01 00:23:22 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 09:45:45 -08:00
										 |  |  |   all_markdown_files = [...all_markdown_files, ...all_generated_markdown_files]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-17 15:15:39 -05:00
										 |  |  |   if (!process.env.CI) { | 
					
						
							|  |  |  |     // If not in CI, we also include "untracked" files.
 | 
					
						
							|  |  |  |     const untracked_files = execSync( | 
					
						
							|  |  |  |       "(git ls-files --full-name --others --exclude-standard .. | grep '.md$') || true" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |       .toString() | 
					
						
							|  |  |  |       .trim() | 
					
						
							|  |  |  |       .split("\n") | 
					
						
							| 
									
										
										
										
											2022-02-18 09:45:45 -08:00
										 |  |  |       .filter((filepath) => !all_generated_markdown_files.includes(filepath)); | 
					
						
							| 
									
										
										
										
											2022-02-17 15:15:39 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (untracked_files.length > 0) { | 
					
						
							| 
									
										
										
										
											2022-08-15 05:43:17 +00:00
										 |  |  |       console.log( | 
					
						
							|  |  |  |         `Including untracked files in docs list: [${untracked_files}]` | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2022-02-17 15:15:39 -05:00
										 |  |  |       all_markdown_files = [...all_markdown_files, ...untracked_files]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-08-15 05:43:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // But we should also exclude any files that have been deleted.
 | 
					
						
							|  |  |  |     const deleted_files = execSync( | 
					
						
							|  |  |  |       "(git ls-files --full-name --deleted --exclude-standard .. | grep '.md$') || true" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |       .toString() | 
					
						
							|  |  |  |       .trim() | 
					
						
							|  |  |  |       .split("\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (deleted_files.length > 0) { | 
					
						
							|  |  |  |       console.log(`Removing deleted files from docs list: [${deleted_files}]`); | 
					
						
							|  |  |  |       all_markdown_files = all_markdown_files.filter( | 
					
						
							|  |  |  |         (filepath) => !deleted_files.includes(filepath) | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-02-17 15:15:39 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const filter_patterns = [ | 
					
						
							|  |  |  |     // We don't need our issue and pull request templates.
 | 
					
						
							|  |  |  |     /^\.github\//, | 
					
						
							|  |  |  |     // Ignore everything within this directory.
 | 
					
						
							|  |  |  |     /^docs-website\//, | 
					
						
							|  |  |  |     // Don't want hosted docs for these.
 | 
					
						
							| 
									
										
										
										
											2021-04-23 00:31:06 -07:00
										 |  |  |     /^contrib\//, | 
					
						
							| 
									
										
										
										
											2022-02-17 15:15:39 -05:00
										 |  |  |     // Keep main docs for kubernetes, but skip the inner docs.
 | 
					
						
							| 
									
										
										
										
											2021-07-08 19:27:19 -07:00
										 |  |  |     /^datahub-kubernetes\//, | 
					
						
							| 
									
										
										
										
											2022-02-17 15:15:39 -05:00
										 |  |  |     // Various other docs/directories to ignore.
 | 
					
						
							| 
									
										
										
										
											2022-02-18 09:45:45 -08:00
										 |  |  |     /^metadata-models\/docs\//, // these are used to generate docs, so we don't want to consider them here
 | 
					
						
							| 
									
										
										
										
											2022-05-02 00:18:15 -07:00
										 |  |  |     /^metadata-ingestion\/archived\//, // these are archived, so we don't want to consider them here
 | 
					
						
							|  |  |  |     /^metadata-ingestion\/docs\/sources\//, // these are used to generate docs, so we don't want to consider them here
 | 
					
						
							| 
									
										
										
										
											2023-03-29 17:13:43 -04:00
										 |  |  |     /^metadata-ingestion\/tests\//, | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |     /^metadata-ingestion-examples\//, | 
					
						
							| 
									
										
										
										
											2021-09-01 11:51:14 -07:00
										 |  |  |     /^docker\/(?!README|datahub-upgrade|airflow\/local_airflow)/, // Drop all but a few docker docs.
 | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |     /^docs\/docker\/README\.md/, // This one is just a pointer to another file.
 | 
					
						
							| 
									
										
										
										
											2021-03-15 22:29:11 -07:00
										 |  |  |     /^docs\/README\.md/, // This one is just a pointer to the hosted docs site.
 | 
					
						
							| 
									
										
										
										
											2022-03-01 00:23:22 +05:30
										 |  |  |     /^\s*$/, //Empty string
 | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |   ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const markdown_files = all_markdown_files.filter((filepath) => { | 
					
						
							|  |  |  |     return !filter_patterns.some((rule) => rule.test(filepath)); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   return markdown_files; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const markdown_files = list_markdown_files(); | 
					
						
							| 
									
										
										
										
											2022-03-01 00:23:22 +05:30
										 |  |  | // for (let markdown_file of markdown_files) {
 | 
					
						
							|  |  |  | //   console.log("markdown_file", markdown_file);
 | 
					
						
							|  |  |  | // }
 | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function get_id(filepath: string): string { | 
					
						
							|  |  |  |   // Removes the file extension (e.g. md).
 | 
					
						
							|  |  |  |   const id = filepath.replace(/\.[^/.]+$/, ""); | 
					
						
							|  |  |  |   // console.log(id);
 | 
					
						
							|  |  |  |   return id; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const hardcoded_slugs = { | 
					
						
							| 
									
										
										
										
											2022-08-26 16:29:01 -05:00
										 |  |  |   "README.md": "/introduction", | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function get_slug(filepath: string): string { | 
					
						
							| 
									
										
										
										
											2022-02-17 15:15:39 -05:00
										 |  |  |   // The slug is the URL path to the page.
 | 
					
						
							|  |  |  |   // In the actual site, all slugs are prefixed with /docs.
 | 
					
						
							|  |  |  |   // There's no need to do this cleanup, but it does make the URLs a bit more aesthetic.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |   if (filepath in hardcoded_slugs) { | 
					
						
							| 
									
										
										
										
											2023-09-04 13:37:18 +09:00
										 |  |  |     return hardcoded_slugs[filepath as keyof typeof hardcoded_slugs]; | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let slug = get_id(filepath); | 
					
						
							|  |  |  |   if (slug.startsWith("docs/")) { | 
					
						
							|  |  |  |     slug = slug.slice(5); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   slug = `/${slug}`; | 
					
						
							|  |  |  |   if (slug.endsWith("/README")) { | 
					
						
							|  |  |  |     slug = slug.slice(0, -7); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   slug = slug.toLowerCase(); | 
					
						
							|  |  |  |   return slug; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const hardcoded_titles = { | 
					
						
							|  |  |  |   "README.md": "Introduction", | 
					
						
							| 
									
										
										
										
											2022-05-31 19:01:44 -07:00
										 |  |  |   "docs/actions/README.md": "Introduction", | 
					
						
							|  |  |  |   "docs/actions/concepts.md": "Concepts", | 
					
						
							|  |  |  |   "docs/actions/quickstart.md": "Quickstart", | 
					
						
							| 
									
										
										
										
											2024-07-30 09:52:51 +09:00
										 |  |  |   "docs/saas.md": "DataHub Cloud", | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2021-08-10 19:46:02 -04:00
										 |  |  | // titles that have been hardcoded in sidebars.js
 | 
					
						
							|  |  |  | // (for cases where doc is reference multiple times with different titles)
 | 
					
						
							|  |  |  | const sidebarsjs_hardcoded_titles = [ | 
					
						
							|  |  |  |   "metadata-ingestion/README.md", | 
					
						
							|  |  |  |   "metadata-ingestion/source_docs/s3.md", | 
					
						
							| 
									
										
										
										
											2021-09-22 17:30:15 -07:00
										 |  |  |   "docs/api/graphql/overview.md", | 
					
						
							| 
									
										
										
										
											2021-08-10 19:46:02 -04:00
										 |  |  | ]; | 
					
						
							| 
									
										
										
										
											2021-05-25 18:51:24 -07:00
										 |  |  | const hardcoded_hide_title = ["README.md"]; | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-15 22:29:11 -07:00
										 |  |  | const hardcoded_descriptions = { | 
					
						
							|  |  |  |   // Only applied if title is also overridden.
 | 
					
						
							|  |  |  |   "README.md": | 
					
						
							|  |  |  |     "DataHub is a data discovery application built on an extensible metadata platform that helps you tame the complexity of diverse data ecosystems.", | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-08 15:39:49 -08:00
										 |  |  | // FIXME: Eventually, we'd like to fix all of the broken links within these files.
 | 
					
						
							|  |  |  | const allowed_broken_links = [ | 
					
						
							|  |  |  |   "docs/developers.md", | 
					
						
							|  |  |  |   "docs/how/customize-elasticsearch-query-template.md", | 
					
						
							|  |  |  |   "docs/how/graph-onboarding.md", | 
					
						
							|  |  |  |   "docs/how/search-onboarding.md", | 
					
						
							| 
									
										
										
										
											2021-03-15 22:29:11 -07:00
										 |  |  |   "docs/how/build-metadata-service.md", | 
					
						
							| 
									
										
										
										
											2021-03-08 15:39:49 -08:00
										 |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | function markdown_guess_title( | 
					
						
							|  |  |  |   contents: matter.GrayMatterFile<string>, | 
					
						
							|  |  |  |   filepath: string | 
					
						
							|  |  |  | ): void { | 
					
						
							| 
									
										
										
										
											2021-08-10 19:46:02 -04:00
										 |  |  |   if (sidebarsjs_hardcoded_titles.includes(filepath)) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |   if (contents.data.title) { | 
					
						
							| 
									
										
										
										
											2021-05-24 12:23:03 -07:00
										 |  |  |     contents.data.sidebar_label = contents.data.title; | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let title: string; | 
					
						
							|  |  |  |   if (filepath in hardcoded_titles) { | 
					
						
							| 
									
										
										
										
											2023-09-04 13:37:18 +09:00
										 |  |  |     title = hardcoded_titles[filepath as keyof typeof hardcoded_titles]; | 
					
						
							| 
									
										
										
										
											2021-03-15 22:29:11 -07:00
										 |  |  |     if (filepath in hardcoded_descriptions) { | 
					
						
							| 
									
										
										
										
											2023-09-04 13:37:18 +09:00
										 |  |  |       contents.data.description = | 
					
						
							|  |  |  |         hardcoded_descriptions[filepath as keyof typeof hardcoded_descriptions]; | 
					
						
							| 
									
										
										
										
											2021-03-15 22:29:11 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-05-26 17:17:09 -07:00
										 |  |  |     if (hardcoded_hide_title.includes(filepath)) { | 
					
						
							| 
									
										
										
										
											2021-05-25 18:51:24 -07:00
										 |  |  |       contents.data.hide_title = true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     // Find first h1 header and use it as the title.
 | 
					
						
							|  |  |  |     const headers = contents.content.match(/^# (.+)$/gm); | 
					
						
							| 
									
										
										
										
											2021-08-08 16:40:51 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (!headers) { | 
					
						
							|  |  |  |       throw new Error( | 
					
						
							|  |  |  |         `${filepath} must have at least one h1 header for setting the title` | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |     if (headers.length > 1 && contents.content.indexOf("```") < 0) { | 
					
						
							|  |  |  |       throw new Error(`too many h1 headers in ${filepath}`); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     title = headers[0].slice(2).trim(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   contents.data.title = title; | 
					
						
							| 
									
										
										
										
											2021-05-24 12:23:03 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   let sidebar_label = title; | 
					
						
							|  |  |  |   if (sidebar_label.startsWith("DataHub ")) { | 
					
						
							|  |  |  |     sidebar_label = sidebar_label.slice(8).trim(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-09-01 18:11:14 -05:00
										 |  |  |   if (sidebar_label.startsWith("About DataHub ")) { | 
					
						
							|  |  |  |     sidebar_label = sidebar_label.slice(14).trim(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-08-26 16:29:01 -05:00
										 |  |  |   if (sidebar_label != title) { | 
					
						
							|  |  |  |     contents.data.sidebar_label = sidebar_label; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function markdown_add_edit_url( | 
					
						
							|  |  |  |   contents: matter.GrayMatterFile<string>, | 
					
						
							|  |  |  |   filepath: string | 
					
						
							|  |  |  | ): void { | 
					
						
							|  |  |  |   const editUrl = `${GITHUB_EDIT_URL}/${filepath}`; | 
					
						
							|  |  |  |   contents.data.custom_edit_url = editUrl; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function markdown_add_slug( | 
					
						
							|  |  |  |   contents: matter.GrayMatterFile<string>, | 
					
						
							|  |  |  |   filepath: string | 
					
						
							|  |  |  | ): void { | 
					
						
							|  |  |  |   if (contents.data.slug) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const slug = get_slug(filepath); | 
					
						
							|  |  |  |   contents.data.slug = slug; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-13 11:37:24 -07:00
										 |  |  | // function copy_platform_logos(): void {
 | 
					
						
							|  |  |  | //   execSync("mkdir -p " + OUTPUT_DIRECTORY + "/imgs/platform-logos");
 | 
					
						
							|  |  |  | //   execSync(
 | 
					
						
							|  |  |  | //     "cp -r ../datahub-web-react/src/images " +
 | 
					
						
							|  |  |  | //       OUTPUT_DIRECTORY +
 | 
					
						
							|  |  |  | //       "/imgs/platform-logos"
 | 
					
						
							|  |  |  | //   );
 | 
					
						
							|  |  |  | // }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-16 16:55:51 -07:00
										 |  |  | function preprocess_url(url: string): string { | 
					
						
							|  |  |  |   return url.trim().replace(/^<(.+)>$/, "$1"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-12 16:51:24 -05:00
										 |  |  | function trim_anchor_link(url: string): string { | 
					
						
							|  |  |  |   return url.replace(/#.+$/, ""); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | function new_url(original: string, filepath: string): string { | 
					
						
							| 
									
										
										
										
											2021-03-05 12:20:31 -08:00
										 |  |  |   if (original.toLowerCase().startsWith(HOSTED_SITE_URL)) { | 
					
						
							|  |  |  |     // For absolute links to the hosted docs site, we transform them into local ones.
 | 
					
						
							|  |  |  |     // Note that HOSTED_SITE_URL does not have a trailing slash, so after the replacement,
 | 
					
						
							|  |  |  |     // the url will start with a slash.
 | 
					
						
							|  |  |  |     return original.replace(HOSTED_SITE_URL, ""); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |   if (original.startsWith("http://") || original.startsWith("https://")) { | 
					
						
							|  |  |  |     if ( | 
					
						
							|  |  |  |       (original | 
					
						
							|  |  |  |         .toLowerCase() | 
					
						
							| 
									
										
										
										
											2022-03-18 22:12:19 +01:00
										 |  |  |         .startsWith("https://github.com/datahub-project/datahub/blob") || | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |         original | 
					
						
							|  |  |  |           .toLowerCase() | 
					
						
							| 
									
										
										
										
											2022-03-18 22:12:19 +01:00
										 |  |  |           .startsWith("https://github.com/datahub-project/datahub/tree")) && | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |       (original.endsWith(".md") || original.endsWith(".pdf")) | 
					
						
							|  |  |  |     ) { | 
					
						
							|  |  |  |       throw new Error(`absolute link (${original}) found in ${filepath}`); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return original; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (original.startsWith("#")) { | 
					
						
							|  |  |  |     // These are anchor links that reference within the document itself.
 | 
					
						
							|  |  |  |     return original; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Now we assume this is a local reference.
 | 
					
						
							| 
									
										
										
										
											2024-12-12 16:51:24 -05:00
										 |  |  |   const suffix = path.extname(trim_anchor_link(original)); | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |   if ( | 
					
						
							|  |  |  |     suffix == "" || | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |       ".java", | 
					
						
							|  |  |  |       ".conf", | 
					
						
							|  |  |  |       ".xml", | 
					
						
							|  |  |  |       ".pdl", | 
					
						
							|  |  |  |       ".json", | 
					
						
							|  |  |  |       ".py", | 
					
						
							|  |  |  |       ".ts", | 
					
						
							|  |  |  |       ".yml", | 
					
						
							| 
									
										
										
										
											2022-06-08 00:52:26 +02:00
										 |  |  |       ".yaml", | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |       ".sh", | 
					
						
							|  |  |  |       ".env", | 
					
						
							|  |  |  |       ".sql", | 
					
						
							| 
									
										
										
										
											2022-02-17 15:15:39 -05:00
										 |  |  |       // Using startsWith since some URLs will be .ext#LINENO
 | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |     ].some((ext) => suffix.startsWith(ext)) | 
					
						
							|  |  |  |   ) { | 
					
						
							|  |  |  |     // A reference to a file or directory in the Github repo.
 | 
					
						
							|  |  |  |     const relation = path.dirname(filepath); | 
					
						
							| 
									
										
										
										
											2021-03-07 10:46:27 -08:00
										 |  |  |     const updated_path = path.normalize(`${relation}/${original}`); | 
					
						
							| 
									
										
										
										
											2024-12-12 16:51:24 -05:00
										 |  |  |     const check_path = trim_anchor_link(updated_path); | 
					
						
							| 
									
										
										
										
											2021-03-08 15:39:49 -08:00
										 |  |  |     if ( | 
					
						
							|  |  |  |       !fs.existsSync(`../${check_path}`) && | 
					
						
							|  |  |  |       actually_in_sidebar(filepath) && | 
					
						
							|  |  |  |       !allowed_broken_links.includes(filepath) | 
					
						
							|  |  |  |     ) { | 
					
						
							| 
									
										
										
										
											2021-03-07 10:46:27 -08:00
										 |  |  |       // Detects when the path is a dangling reference, according to the locally
 | 
					
						
							|  |  |  |       // checked out repo.
 | 
					
						
							|  |  |  |       throw new Error( | 
					
						
							| 
									
										
										
										
											2021-03-08 15:39:49 -08:00
										 |  |  |         `broken github repo link to ${updated_path} in ${filepath}` | 
					
						
							| 
									
										
										
										
											2021-03-07 10:46:27 -08:00
										 |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     const updated_url = `${GITHUB_BROWSE_URL}/${updated_path}`; | 
					
						
							|  |  |  |     return updated_url; | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |   } else if (suffix.startsWith(".md")) { | 
					
						
							|  |  |  |     // Leave as-is.
 | 
					
						
							|  |  |  |     // We use startsWith above so that we can allow anchor tags on links.
 | 
					
						
							|  |  |  |     return original; | 
					
						
							|  |  |  |   } else if ([".png", ".svg", ".gif", ".pdf"].includes(suffix)) { | 
					
						
							|  |  |  |     // Let docusaurus bundle these as static assets.
 | 
					
						
							|  |  |  |     const up_levels = (filepath.match(/\//g) ?? []).length; | 
					
						
							|  |  |  |     const relation = path.dirname(filepath); | 
					
						
							|  |  |  |     const updated = path.normalize( | 
					
						
							|  |  |  |       `${"../".repeat(up_levels + 2)}/${relation}/${original}` | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2022-05-02 00:18:15 -07:00
										 |  |  |     //console.log(`Rewriting ${original} ${filepath} as ${updated}`);
 | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |     return updated; | 
					
						
							|  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2021-03-07 10:46:27 -08:00
										 |  |  |     throw new Error(`unknown extension - ${original} in ${filepath}`); | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function markdown_rewrite_urls( | 
					
						
							|  |  |  |   contents: matter.GrayMatterFile<string>, | 
					
						
							|  |  |  |   filepath: string | 
					
						
							|  |  |  | ): void { | 
					
						
							|  |  |  |   const new_content = contents.content | 
					
						
							|  |  |  |     .replace( | 
					
						
							|  |  |  |       // Look for the [text](url) syntax. Note that this will also capture images.
 | 
					
						
							|  |  |  |       //
 | 
					
						
							|  |  |  |       // We do a little bit of parenthesis matching here to account for parens in URLs.
 | 
					
						
							|  |  |  |       // See https://stackoverflow.com/a/17759264 for explanation of the second capture group.
 | 
					
						
							| 
									
										
										
										
											2021-10-26 14:36:25 -05:00
										 |  |  |       /\[(.*?)\]\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/g, | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |       (_, text, url) => { | 
					
						
							| 
									
										
										
										
											2025-04-16 16:55:51 -07:00
										 |  |  |         const updated = new_url(preprocess_url(url), filepath); | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |         return `[${text}](${updated})`; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     .replace( | 
					
						
							|  |  |  |       // Also look for the [text]: url syntax.
 | 
					
						
							| 
									
										
										
										
											2023-02-22 15:45:45 -06:00
										 |  |  |       /^\[([^^\n\r]+?)\]\s*:\s*(.+?)\s*$/gm, | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |       (_, text, url) => { | 
					
						
							| 
									
										
										
										
											2025-04-16 16:55:51 -07:00
										 |  |  |         const updated = new_url(preprocess_url(url), filepath); | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |         return `[${text}]: ${updated}`; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   contents.content = new_content; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function markdown_enable_specials( | 
					
						
							|  |  |  |   contents: matter.GrayMatterFile<string>, | 
					
						
							|  |  |  |   filepath: string | 
					
						
							|  |  |  | ): void { | 
					
						
							|  |  |  |   const new_content = contents.content | 
					
						
							|  |  |  |     .replace(/^<!--HOSTED_DOCS_ONLY$/gm, "") | 
					
						
							|  |  |  |     .replace(/^HOSTED_DOCS_ONLY-->$/gm, ""); | 
					
						
							|  |  |  |   contents.content = new_content; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-30 05:32:21 +05:30
										 |  |  | function markdown_process_inline_directives( | 
					
						
							|  |  |  |   contents: matter.GrayMatterFile<string>, | 
					
						
							|  |  |  |   filepath: string | 
					
						
							|  |  |  | ): void { | 
					
						
							|  |  |  |   const new_content = contents.content.replace( | 
					
						
							| 
									
										
										
										
											2025-05-22 17:35:14 +09:00
										 |  |  |     /^(\s*){{(\s*)inline\s+(\S+)(\s+)(show_path_as_comment\s+)?(\s*)}}$/gm, | 
					
						
							|  |  |  |     ( | 
					
						
							|  |  |  |       _, | 
					
						
							|  |  |  |       indent: string, | 
					
						
							|  |  |  |       __, | 
					
						
							|  |  |  |       inline_file_path: string, | 
					
						
							|  |  |  |       ___, | 
					
						
							|  |  |  |       show_path_as_comment: string | 
					
						
							|  |  |  |     ) => { | 
					
						
							| 
									
										
										
										
											2023-03-30 05:32:21 +05:30
										 |  |  |       if (!inline_file_path.startsWith("/")) { | 
					
						
							|  |  |  |         throw new Error(`inline path must be absolute: ${inline_file_path}`); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-04 18:40:19 +05:30
										 |  |  |       // console.log(`Inlining ${inline_file_path} into ${filepath}`);
 | 
					
						
							| 
									
										
										
										
											2023-03-30 05:32:21 +05:30
										 |  |  |       const referenced_file = fs.readFileSync( | 
					
						
							|  |  |  |         path.join("..", inline_file_path), | 
					
						
							|  |  |  |         "utf8" | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // TODO: Add support for start_after_line and end_before_line arguments
 | 
					
						
							|  |  |  |       // that can be used to limit the inlined content to a specific range of lines.
 | 
					
						
							|  |  |  |       let new_contents = ""; | 
					
						
							|  |  |  |       if (show_path_as_comment) { | 
					
						
							| 
									
										
										
										
											2025-05-22 17:35:14 +09:00
										 |  |  |         new_contents += `${indent}# Inlined from ${inline_file_path}\n`; | 
					
						
							| 
									
										
										
										
											2023-03-30 05:32:21 +05:30
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-05-22 17:35:14 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Add indentation to each line of the referenced file
 | 
					
						
							|  |  |  |       new_contents += referenced_file | 
					
						
							|  |  |  |         .split("\n") | 
					
						
							|  |  |  |         .map((line) => `${indent}${line}`) | 
					
						
							|  |  |  |         .join("\n"); | 
					
						
							| 
									
										
										
										
											2023-03-30 05:32:21 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |       return new_contents; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  |   contents.content = new_content; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-10 10:35:13 -08:00
										 |  |  | function markdown_process_command_output( | 
					
						
							|  |  |  |   contents: matter.GrayMatterFile<string>, | 
					
						
							|  |  |  |   filepath: string | 
					
						
							|  |  |  | ): void { | 
					
						
							|  |  |  |   const new_content = contents.content.replace( | 
					
						
							|  |  |  |     /^{{\s*command-output\s*([\s\S]*?)\s*}}$/gm, | 
					
						
							|  |  |  |     (_, command: string) => { | 
					
						
							|  |  |  |       try { | 
					
						
							|  |  |  |         // Change to repo root directory before executing command
 | 
					
						
							|  |  |  |         const repoRoot = path.resolve(__dirname, ".."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         console.log(`Executing command: ${command}`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Execute the command and capture output
 | 
					
						
							|  |  |  |         const output = execSync(command, { | 
					
						
							|  |  |  |           cwd: repoRoot, | 
					
						
							|  |  |  |           encoding: "utf8", | 
					
						
							|  |  |  |           stdio: ["pipe", "pipe", "pipe"], | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Return the command output
 | 
					
						
							|  |  |  |         return output.trim(); | 
					
						
							|  |  |  |       } catch (error: any) { | 
					
						
							|  |  |  |         // If there's an error, include it as a comment
 | 
					
						
							|  |  |  |         const errorMessage = error.stderr | 
					
						
							|  |  |  |           ? error.stderr.toString() | 
					
						
							|  |  |  |           : error.message; | 
					
						
							|  |  |  |         return `${ | 
					
						
							|  |  |  |           error.stdout ? error.stdout.toString().trim() : "" | 
					
						
							|  |  |  |         }\n<!-- Error: ${errorMessage.trim()} -->`;
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  |   contents.content = new_content; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  | function markdown_sanitize_and_linkify(content: string): string { | 
					
						
							|  |  |  |   // MDX escaping
 | 
					
						
							|  |  |  |   content = content.replace(/</g, "<"); | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |   // Link to user profiles.
 | 
					
						
							|  |  |  |   content = content.replace(/@([\w-]+)\b/g, "[@$1](https://github.com/$1)"); | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |   // Link to issues/pull requests.
 | 
					
						
							|  |  |  |   content = content.replace( | 
					
						
							|  |  |  |     /#(\d+)\b/g, | 
					
						
							| 
									
										
										
										
											2022-03-18 22:12:19 +01:00
										 |  |  |     "[#$1](https://github.com/datahub-project/datahub/pull/$1)" | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-17 15:15:39 -05:00
										 |  |  |   // Prettify bare links to PRs.
 | 
					
						
							|  |  |  |   content = content.replace( | 
					
						
							|  |  |  |     /(\s+)(https:\/\/github\.com\/linkedin\/datahub\/pull\/(\d+))(\s+|$)/g, | 
					
						
							|  |  |  |     "$1[#$3]($2)$4" | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |   return content; | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  | function pretty_format_date(datetime: string): string { | 
					
						
							|  |  |  |   const d = new Date(Date.parse(datetime)); | 
					
						
							| 
									
										
										
										
											2022-08-11 21:51:09 +00:00
										 |  |  |   return d.toISOString().split("T")[0]; | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function make_link_anchor(text: string): string { | 
					
						
							|  |  |  |   return text.replace(/\./g, "-"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function generate_releases_markdown(): Promise< | 
					
						
							|  |  |  |   matter.GrayMatterFile<string> | 
					
						
							|  |  |  | > { | 
					
						
							|  |  |  |   const contents = matter(`---
 | 
					
						
							|  |  |  | title: DataHub Releases | 
					
						
							|  |  |  | sidebar_label: Releases | 
					
						
							|  |  |  | slug: /releases | 
					
						
							| 
									
										
										
										
											2022-03-18 22:12:19 +01:00
										 |  |  | custom_edit_url: https://github.com/datahub-project/datahub/blob/master/docs-website/generateDocsDir.ts
 | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  | --- | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-17 15:15:39 -05:00
										 |  |  | # DataHub Releases | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Summary\n\n`);
 | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-31 15:31:15 -07:00
										 |  |  |   const releases_list_full = await octokit.rest.repos.listReleases({ | 
					
						
							| 
									
										
										
										
											2022-08-11 21:51:09 +00:00
										 |  |  |     owner: "datahub-project", | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |     repo: "datahub", | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2025-03-31 15:31:15 -07:00
										 |  |  |   const releases_list = releases_list_full.data.filter( | 
					
						
							|  |  |  |     (release) => !release.prerelease && !release.draft | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-11 21:51:09 +00:00
										 |  |  |   // We only embed release notes for releases in the last 3 months.
 | 
					
						
							|  |  |  |   const release_notes_date_cutoff = new Date( | 
					
						
							|  |  |  |     Date.now() - 1000 * 60 * 60 * 24 * 30 * 3 | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |   // Construct a summary table.
 | 
					
						
							|  |  |  |   const releaseNoteVersions = new Set(); | 
					
						
							|  |  |  |   contents.content += "| Version | Release Date | Links |\n"; | 
					
						
							|  |  |  |   contents.content += "| ------- | ------------ | ----- |\n"; | 
					
						
							| 
									
										
										
										
											2025-03-31 15:31:15 -07:00
										 |  |  |   for (const release of releases_list) { | 
					
						
							| 
									
										
										
										
											2022-08-11 21:51:09 +00:00
										 |  |  |     const release_date = new Date(Date.parse(release.created_at)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |     let row = `| **${release.tag_name}** | ${pretty_format_date( | 
					
						
							|  |  |  |       release.created_at | 
					
						
							|  |  |  |     )} |`;
 | 
					
						
							| 
									
										
										
										
											2022-08-11 21:51:09 +00:00
										 |  |  |     if (release_date > release_notes_date_cutoff) { | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |       row += `[Release Notes](#${make_link_anchor(release.tag_name)}), `; | 
					
						
							|  |  |  |       releaseNoteVersions.add(release.tag_name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     row += `[View on GitHub](${release.html_url}) |\n`; | 
					
						
							| 
									
										
										
										
											2022-08-11 21:51:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |     contents.content += row; | 
					
						
							| 
									
										
										
										
											2021-05-11 11:17:53 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |   contents.content += "\n\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Full details
 | 
					
						
							| 
									
										
										
										
											2025-03-31 15:31:15 -07:00
										 |  |  |   for (const release of releases_list) { | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |     let body: string; | 
					
						
							| 
									
										
										
										
											2025-06-04 15:42:12 +09:00
										 |  |  |     if (release.tag_name === "v1.1.0") { | 
					
						
							|  |  |  |       body = `View the [release notes](${release.html_url}) for ${release.name} on GitHub.`; | 
					
						
							|  |  |  |     } else if (releaseNoteVersions.has(release.tag_name)) { | 
					
						
							| 
									
										
										
										
											2022-08-15 05:43:17 +00:00
										 |  |  |       body = release.body ?? ""; | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |       body = markdown_sanitize_and_linkify(body); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Redo the heading levels. First we find the min heading level, and then
 | 
					
						
							|  |  |  |       // adjust the markdown headings so that the min heading is level 3.
 | 
					
						
							|  |  |  |       const heading_regex = /^(#+)\s/gm; | 
					
						
							|  |  |  |       const max_heading_level = Math.min( | 
					
						
							|  |  |  |         3, | 
					
						
							|  |  |  |         ...[...body.matchAll(heading_regex)].map((v) => v[1].length) | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       body = body.replace( | 
					
						
							|  |  |  |         heading_regex, | 
					
						
							|  |  |  |         `${"#".repeat(3 - max_heading_level)}$1 ` | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       // Link to GitHub.
 | 
					
						
							|  |  |  |       body = `View the [release notes](${release.html_url}) for ${release.name} on GitHub.`; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const info = `## [${release.name}](${ | 
					
						
							|  |  |  |       release.html_url | 
					
						
							|  |  |  |     }) {#${make_link_anchor(release.tag_name)}} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Released on ${pretty_format_date(release.created_at)} by [@${ | 
					
						
							|  |  |  |       release.author.login | 
					
						
							|  |  |  |     }](${release.author.html_url}). | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ${body}\n\n`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     contents.content += info; | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return contents; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function write_markdown_file( | 
					
						
							|  |  |  |   contents: matter.GrayMatterFile<string>, | 
					
						
							|  |  |  |   output_filepath: string | 
					
						
							|  |  |  | ): void { | 
					
						
							|  |  |  |   const pathname = path.dirname(output_filepath); | 
					
						
							|  |  |  |   fs.mkdirSync(pathname, { recursive: true }); | 
					
						
							| 
									
										
										
										
											2022-05-02 00:18:15 -07:00
										 |  |  |   try { | 
					
						
							|  |  |  |     fs.writeFileSync(output_filepath, contents.stringify("")); | 
					
						
							|  |  |  |   } catch (error) { | 
					
						
							|  |  |  |     console.log(`Failed to write file ${output_filepath}`); | 
					
						
							|  |  |  |     console.log(`contents = ${contents}`); | 
					
						
							|  |  |  |     throw error; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-03-05 00:12:12 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | (async function main() { | 
					
						
							|  |  |  |   for (const filepath of markdown_files) { | 
					
						
							| 
									
										
										
										
											2022-05-02 00:18:15 -07:00
										 |  |  |     //console.log("Processing:", filepath);
 | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |     const contents_string = fs.readFileSync(`../${filepath}`).toString(); | 
					
						
							|  |  |  |     const contents = matter(contents_string); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     markdown_guess_title(contents, filepath); | 
					
						
							|  |  |  |     markdown_add_slug(contents, filepath); | 
					
						
							|  |  |  |     markdown_add_edit_url(contents, filepath); | 
					
						
							|  |  |  |     markdown_rewrite_urls(contents, filepath); | 
					
						
							|  |  |  |     markdown_enable_specials(contents, filepath); | 
					
						
							| 
									
										
										
										
											2023-03-30 05:32:21 +05:30
										 |  |  |     markdown_process_inline_directives(contents, filepath); | 
					
						
							| 
									
										
										
										
											2025-01-10 10:35:13 -08:00
										 |  |  |     markdown_process_command_output(contents, filepath); | 
					
						
							| 
									
										
										
										
											2023-03-13 11:37:24 -07:00
										 |  |  |     //copy_platform_logos();
 | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |     // console.log(contents);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const out_path = `${OUTPUT_DIRECTORY}/${filepath}`; | 
					
						
							|  |  |  |     write_markdown_file(contents, out_path); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Generate the releases history.
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     const contents = await generate_releases_markdown(); | 
					
						
							|  |  |  |     write_markdown_file(contents, `${OUTPUT_DIRECTORY}/releases.md`); | 
					
						
							|  |  |  |     markdown_files.push("releases.md"); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Error if a doc is not accounted for in a sidebar.
 | 
					
						
							| 
									
										
										
										
											2022-05-02 00:18:15 -07:00
										 |  |  |   const autogenerated_sidebar_directories = [ | 
					
						
							|  |  |  |     "docs/generated/metamodel", | 
					
						
							|  |  |  |     "docs/generated/ingestion", | 
					
						
							| 
									
										
										
										
											2022-05-31 19:01:44 -07:00
										 |  |  |     "docs/actions/actions", | 
					
						
							|  |  |  |     "docs/actions/events", | 
					
						
							|  |  |  |     "docs/actions/sources", | 
					
						
							|  |  |  |     "docs/actions/guides", | 
					
						
							| 
									
										
										
										
											2022-05-02 00:18:15 -07:00
										 |  |  |     "metadata-ingestion/archived", | 
					
						
							| 
									
										
										
										
											2023-03-23 00:58:52 +05:30
										 |  |  |     "metadata-ingestion/sink_docs", | 
					
						
							| 
									
										
										
										
											2022-08-26 16:29:01 -05:00
										 |  |  |     "docs/what", | 
					
						
							|  |  |  |     "docs/wip", | 
					
						
							| 
									
										
										
										
											2022-05-02 00:18:15 -07:00
										 |  |  |   ]; | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |   for (const filepath of markdown_files) { | 
					
						
							|  |  |  |     if ( | 
					
						
							|  |  |  |       autogenerated_sidebar_directories.some((dir) => filepath.startsWith(dir)) | 
					
						
							|  |  |  |     ) { | 
					
						
							|  |  |  |       // The sidebars for these directories is automatically generated,
 | 
					
						
							|  |  |  |       // so we don't need check that they're in the sidebar.
 | 
					
						
							|  |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (!accounted_for_in_sidebar(filepath)) { | 
					
						
							| 
									
										
										
										
											2025-06-04 16:33:08 -07:00
										 |  |  |       console.warn( | 
					
						
							|  |  |  |         `File not accounted for in sidebar: ${filepath} - consider adding it to docs-website/sidebars.js or explicitly ignoring it` | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-03-22 21:31:32 +05:30
										 |  |  |   // TODO: copy over the source json schemas + other artifacts.
 | 
					
						
							| 
									
										
										
										
											2021-06-29 10:41:44 -07:00
										 |  |  | })(); |