Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 12 additions & 24 deletions public/js/avrodoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ function AvroDoc() {
}

(function () {
var popoverData = {};

function loadPopoverData() {
var el = document.getElementById("popover-data");
if (el) {
try {
popoverData = JSON.parse(el.textContent || "{}");
} catch {
/* ignore */
}
}
}

var showTimer = null;
var hideTimer = null;
var activePopover = null;
Expand Down Expand Up @@ -58,23 +45,25 @@ function AvroDoc() {
if (bootstrap.Popover.getInstance(el)) return;

var href = el.getAttribute("href") || "";
var urlSegments = href.split("/");
if (urlSegments.length < 4) return;
var schemaPopovers = popoverData[decodeURIComponent(urlSegments[2])];
if (!schemaPopovers) return;
var popover = schemaPopovers[decodeURIComponent(urlSegments[3])];
if (!popover) return;
var section = findSection(href);
if (!section) return;

var nsEl = section.querySelector("h2.namespace");
var nameEl = section.querySelector("h1.type-name");
var titleHtml = "";
if (nsEl) titleHtml += '<span class="namespace">' + nsEl.innerHTML + ".</span>";
if (nameEl) titleHtml += '<span class="type-name">' + nameEl.innerHTML + "</span>";

var detailsEl = section.querySelector(".type-details");

var bsPopover = new bootstrap.Popover(el, {
trigger: "manual",
animation: false,
placement: "bottom",
container: "body",
title: function () {
return popover.title;
},
title: titleHtml,
content: function () {
return popover.content;
return detailsEl ? detailsEl.innerHTML : section.innerHTML;
},
html: true,
sanitize: false,
Expand Down Expand Up @@ -175,7 +164,6 @@ function AvroDoc() {
});

document.addEventListener("DOMContentLoaded", function () {
loadPopoverData();
handleRoute();
setupSearch();
});
Expand Down
24 changes: 0 additions & 24 deletions src/static_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,28 +203,6 @@ function renderSections(ctx) {
return sections.join("\n");
}

/**
* Build the popover data JSON string (pre-rendered title+content for each named type).
* @param {{ schema_by_name: Record<string, any> }} ctx
* @returns {string}
*/
function buildPopoverData(ctx) {
/** @type {Record<string, Record<string, {title: string, content: string}>>} */
const popoverData = {};

for (const [filename, schema] of Object.entries(ctx.schema_by_name)) {
popoverData[filename] = {};
for (const [qualified_name, type] of Object.entries(schema.named_types)) {
const title = nunjucksEnv.render("popover_title.njk", type).trim();
const content = nunjucksEnv.render("named_type_details.njk", type);
popoverData[filename][qualified_name] = { title, content };
}
}

// Escape </script> sequences to prevent breaking inline JSON script tags
return JSON.stringify(popoverData).replace(/<\//g, "<\\/");
}

/**
* Generate HTML and CSS
*
Expand Down Expand Up @@ -255,14 +233,12 @@ async function topLevelHTML(title, extra_css_files, options) {

const list_pane_html = renderListPane(ctx);
const sections_html = renderSections(ctx);
const popover_data = buildPopoverData(ctx);

return nunjucksEnv.render("top_level.njk", {
page_title,
content,
list_pane_html,
sections_html,
popover_data,
});
}

Expand Down
2 changes: 0 additions & 2 deletions src/top_level.njk
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
})();
</script>

<script id="popover-data" type="application/json">{{ popover_data | safe }}</script>

{{ content | safe }}
</head>

Expand Down
2 changes: 2 additions & 0 deletions templates/named_type.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% if namespace %}<h2 class="namespace">{{ namespace }}</h2>{% endif %}
<h1 class="type-name">{{ name }}</h1>

<div class="type-details">
{% if versions %}
{% for version in versions %}
{% if version.definitions %}
Expand Down Expand Up @@ -35,3 +36,4 @@
{% endif %}
{% include "named_type_details.njk" %}
{% endif %}
</div>
1 change: 0 additions & 1 deletion templates/popover_title.njk

This file was deleted.