Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show metadata on connector docs #32334

Merged
merged 10 commits into from
Nov 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
cleanup async logic
  • Loading branch information
evantahler committed Nov 10, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit a2e5c71ee0cc892262a67991f740b9d85041d0cc
43 changes: 13 additions & 30 deletions docusaurus/src/remark/docsHeaderDecoration.js
Original file line number Diff line number Diff line change
@@ -3,44 +3,24 @@ const visit = require("unist-util-visit");

const registry_url =
"https://connectors.airbyte.com/files/generated_reports/connector_registry_report.json";
let registry = {};
let loading = false;

/*
This methods makes registry a singleton available to all callers of this plugin.
Only one download will happen for the first callers and all others will use the cached version.
*/
const fetchCatalog = async () => {
if (loading) {
await sleep(500);
return fetchCatalog();
}

if (registry.length > 0) {
return registry;
}

loading = true;
console.log("Fetching connector registry...");
const response = await fetch(registry_url);
registry = await response.json();
console.log(`fetched ${registry.length} connectors form registry`);
loading = false;
};
let registry = [];

const plugin = () => {
let registryFetcher = fetchCatalog();

const transformer = async (ast, vfile) => {
if (!isDocsPage(vfile)) return;

await fetchCatalog();

const pathParts = vfile.path.split("/");
const connectorName = pathParts.pop().split(".")[0];
const connectorType = pathParts.pop();
const dockerRepository = `airbyte/${connectorType.replace(
/s$/,
""
)}-${connectorName}`;

await Promise.resolve(registryFetcher);

const registryEntry = registry.find(
(r) => r.dockerRepository_oss === dockerRepository
);
@@ -68,6 +48,13 @@ const plugin = () => {
return transformer;
};

const fetchCatalog = async () => {
console.log("Fetching connector registry...");
const response = await fetch(registry_url);
registry = await response.json();
console.log(`fetched ${registry.length} connectors form registry`);
};

const buildConnectorHTMLContent = (
evantahler marked this conversation as resolved.
Show resolved Hide resolved
registryEntry,
originalTitle,
@@ -117,10 +104,6 @@ const isDocsPage = (vfile) => {
return true;
};

const sleep = (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};

const capitalizeFirstLetter = (string) => {
return string.charAt(0).toUpperCase() + string.slice(1);
};