Skip to content

Commit

Permalink
Add stickythead dependency and inject it
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonstyle committed Nov 20, 2023
1 parent 4dfd0eb commit ff76d4d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
28 changes: 28 additions & 0 deletions package/src/common/update-html-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ export async function updateHtmlDependencies(config: Configuration) {
// Cookie-Consent
await updateCookieConsent(config, "4.0.0", workingDir);

// Sticky table headers
await updateStickyThead(config, workingDir);

// Clean existing directories
[bsThemesDir, bsDistDir].forEach((dir) => {
if (existsSync(dir)) {
Expand Down Expand Up @@ -594,6 +597,31 @@ async function updateCookieConsent(
info("Done\n");
}


async function updateStickyThead(
config: Configuration,
working: string
) {
const fileName = "stickythead.js";
const url = `https://raw.githubusercontent.com/rohanpujaris/stickythead/master/dist/${fileName}`;
const tempPath = join(working, fileName);

info(`Downloading ${url}`);
await download(url, tempPath);

const targetDir = join(
config.directoryInfo.src,
"resources",
"formats",
"dashboard",
"js"
);
await ensureDir(targetDir);

await Deno.copyFile(tempPath, join(targetDir, fileName));
info("Done\n");
}

async function updateHtmlTools(
version: string,
working: string,
Expand Down
13 changes: 7 additions & 6 deletions src/format/dashboard/format-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ import { InternalError } from "../../core/lib/error.ts";
import { formatResourcePath } from "../../core/resources.ts";
import { ProjectContext } from "../../project/types.ts";
import { registerWriterFormatHandler } from "../format-handlers.ts";
import {
kBootstrapDependencyName,
kPageLayout,
kPageLayoutCustom,
} from "../html/format-html-shared.ts";
import { kPageLayout, kPageLayoutCustom } from "../html/format-html-shared.ts";
import { htmlFormat } from "../html/format-html.ts";

import { join } from "path/mod.ts";
Expand All @@ -60,7 +56,6 @@ import {
import { processSidebars } from "./format-dashboard-sidebar.ts";
import { kTemplatePartials } from "../../command/render/template.ts";
import { processPages } from "./format-dashboard-page.ts";
import { sassLayer } from "../../core/sass.ts";
import { processNavButtons } from "./format-dashboard-navbutton.ts";
import { processNavigation } from "./format-dashboard-website.ts";
import { projectIsWebsite } from "../../project/project-shared.ts";
Expand Down Expand Up @@ -165,6 +160,12 @@ export function dashboardFormat() {
path: formatResourcePath("dashboard", "quarto-dashboard.js"),
});

// Add the sticky headers script
scripts.push({
name: "stickythead.js",
path: formatResourcePath("dashboard", join("js", "stickythead.js")),
});

const componentDir = join(
"bslib",
"components",
Expand Down
2 changes: 2 additions & 0 deletions src/resources/formats/dashboard/js/stickythead.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/resources/formats/dashboard/quarto-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {

manageOverflow();

const markdownTables = document.querySelectorAll(".card-body > table");
for (const markdownTable of markdownTables) {
const scrollableArea = markdownTable.parentElement;
stickyThead.apply([markdownTable], { scrollableArea: scrollableArea });
}

// Fixup any sharing links that require urls
// Append url to any sharing urls
const sharingLinks = window.document.querySelectorAll(
Expand Down

0 comments on commit ff76d4d

Please sign in to comment.