Skip to content

Commit

Permalink
Merge branch 'main' of github.com:quarto-dev/quarto-cli into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Sep 28, 2021
2 parents 13f4e74 + 5379985 commit e4a9521
Show file tree
Hide file tree
Showing 23 changed files with 1,956 additions and 469 deletions.
5 changes: 4 additions & 1 deletion configuration
Expand Up @@ -27,8 +27,11 @@ export TIPPY_JS=6.3.0
export PDF_JS=2.8.335

# javascript search dependencies
export AUTOCOMPLETE_JS=0.38.0
export AUTOCOMPLETE_JS=1.4.0
export FUSE_JS=6.4.6
export ALGOLIA_SEARCH_JS=4.5.1
export ALGOLIA_SEARCH_INSIGHTS_JS=2.0.3


# Quarto Info Version
export QUARTO_VERSION=0.2
Expand Down
42 changes: 39 additions & 3 deletions package/src/common/update-html-dependencies.ts
Expand Up @@ -125,8 +125,6 @@ export async function updateHtmlDepedencies(config: Configuration) {
"FUSE_JS",
workingDir,
(dir: string, version: string) => {
console.log(dir);

// Copy the js file
ensureDirSync(dirname(fuseJs));
Deno.copyFileSync(
Expand All @@ -144,14 +142,32 @@ export async function updateHtmlDepedencies(config: Configuration) {
"projects",
"website",
"search",
"autocomplete.min.js",
"autocomplete.umd.js",
);
await updateUnpkgDependency(
"AUTOCOMPLETE_JS",
"@algolia/autocomplete-js",
"dist/umd/index.production.js",
autocompleteJs,
);
cleanSourceMap(autocompleteJs);

// Autocomplete preset
const autocompletePresetJs = join(
config.directoryInfo.src,
"resources",
"projects",
"website",
"search",
"autocomplete-preset-algolia.umd.js",
);
await updateUnpkgDependency(
"AUTOCOMPLETE_JS",
"@algolia/autocomplete-preset-algolia",
"dist/umd/index.production.js",
autocompletePresetJs,
);
cleanSourceMap(autocompletePresetJs);

// Update PDF JS
await updatePdfJs(
Expand Down Expand Up @@ -439,6 +455,26 @@ async function updateUnpkgDependency(
}
}

async function updateJsDelivrDependency(
versionEnvVar: string,
pkg: string,
filename: string,
target: string,
) {
const version = Deno.env.get(versionEnvVar);
if (version) {
info(`Updating ${pkg}...`);
const url = `https://cdn.jsdelivr.net/npm/${pkg}@${version}/${filename}`;

info(`Downloading ${url} to ${target}`);
ensureDirSync(dirname(target));
await download(url, target);
info("done\n");
} else {
throw new Error(`${versionEnvVar} is not defined`);
}
}

async function updateGithubSourceCodeDependency(
name: string,
repo: string,
Expand Down
9 changes: 9 additions & 0 deletions src/command/render/pandoc.ts
Expand Up @@ -577,7 +577,13 @@ export function resolveDependencies(

const lines: string[] = [];
if (extras.html?.[kDependencies]) {
const copiedDependencies: string[] = [];
for (const dependency of extras.html?.[kDependencies]!) {
// Ensure that we copy (and render HTML for) each named dependency only once
if (copiedDependencies.includes(dependency.name)) {
continue;
}

const dir = dependency.version
? `${dependency.name}-${dependency.version}`
: dependency.name;
Expand Down Expand Up @@ -627,6 +633,9 @@ export function resolveDependencies(
if (dependency.resources) {
dependency.resources.forEach((resource) => copyDep(resource));
}

// Note that we've copied this dependency
copiedDependencies.push(dependency.name);
}
delete extras.html?.[kDependencies];

Expand Down
12 changes: 11 additions & 1 deletion src/format/html/format-html-shared.ts
Expand Up @@ -7,7 +7,7 @@
import { join } from "path/mod.ts";
import { outputVariable, sassVariable } from "../../core/sass.ts";
import { kCodeOverflow } from "../../config/constants.ts";
import { Format } from "../../config/types.ts";
import { Format, FormatDependency } from "../../config/types.ts";

import { formatResourcePath } from "../../core/resources.ts";

Expand All @@ -28,6 +28,16 @@ export const kFootnoteSectionTitle = "footnote-section-title";
export const kDocumentCss = "document-css";
export const kBootstrapDependencyName = "bootstrap";

export const clipboardDependency = () => {
const dependency: FormatDependency = { name: "clipboard" };
dependency.scripts = [];
dependency.scripts.push({
name: "clipboard.min.js",
path: formatResourcePath("html", join("clipboard", "clipboard.min.js")),
});
return dependency;
};

export const quartoRules = () =>
Deno.readTextFileSync(formatResourcePath(
"html",
Expand Down
19 changes: 10 additions & 9 deletions src/format/html/format-html.ts
Expand Up @@ -28,6 +28,7 @@ import {
import {
DependencyFile,
Format,
FormatDependency,
FormatExtras,
kDependencies,
kHtmlPostprocessors,
Expand All @@ -48,6 +49,7 @@ import {
} from "./format-html-bootstrap.ts";

import {
clipboardDependency,
kAnchorSections,
kBootstrapDependencyName,
kCodeCopy,
Expand Down Expand Up @@ -213,6 +215,7 @@ function htmlFormatExtras(format: Format): FormatExtras {
const stylesheets: DependencyFile[] = [];
const bootstrap = formatHasBootstrap(format);
const sassBundles: SassBundle[] = [];
const dependencies: FormatDependency[] = [];

const options: Record<string, unknown> = format.metadata[kComments]
? {
Expand Down Expand Up @@ -293,10 +296,7 @@ function htmlFormatExtras(format: Format): FormatExtras {

// clipboard.js if required
if (options.copyCode) {
scripts.push({
name: "clipboard.min.js",
path: formatResourcePath("html", join("clipboard", "clipboard.min.js")),
});
dependencies.push(clipboardDependency());
}

// anchors if required
Expand Down Expand Up @@ -401,15 +401,16 @@ function htmlFormatExtras(format: Format): FormatExtras {
}

// return extras
dependencies.push({
name: kQuartoHtmlDependency,
scripts,
stylesheets,
});
return {
[kIncludeInHeader]: includeInHeader,
[kIncludeAfterBody]: includeAfterBody,
html: {
[kDependencies]: [{
name: kQuartoHtmlDependency,
scripts,
stylesheets,
}],
[kDependencies]: dependencies,
[kSassBundles]: sassBundles,
[kHtmlPostprocessors]: [htmlFormatPostprocessor(format)],
},
Expand Down
1 change: 1 addition & 0 deletions src/project/types/book/book-config.ts
Expand Up @@ -112,6 +112,7 @@ export async function bookProjectConfig(
site[kOpenGraph] = book[kOpenGraph];
site[kTwitterCard] = book[kTwitterCard];
site[kImage] = book[kImage];
site[kBookSearch] = book[kBookSearch];

// If there is an explicitly set footer use that
if (book[kSiteFooter]) {
Expand Down
3 changes: 2 additions & 1 deletion src/project/types/website/website-config.ts
Expand Up @@ -99,7 +99,8 @@ export function websiteConfig(
| "navbar"
| "sidebar"
| "page-navigation"
| "footer",
| "footer"
| "search",
project?: ProjectConfig,
) {
const site = project?.[kSite] as
Expand Down
34 changes: 25 additions & 9 deletions src/project/types/website/website-navigation.ts
Expand Up @@ -64,8 +64,9 @@ import {
import { projectType } from "../project-types.ts";

import {
websiteSearch,
searchOptions,
websiteSearchDependency,
websiteSearchIncludeInHeader,
websiteSearchSassBundle,
} from "./website-search.ts";

Expand All @@ -90,7 +91,11 @@ import {
NavigationPagination,
websiteNavigationConfig,
} from "./website-shared.ts";
import { kNumberSections, kTocTitle } from "../../../config/constants.ts";
import {
kIncludeInHeader,
kNumberSections,
kTocTitle,
} from "../../../config/constants.ts";
import {
createMarkdownEnvelope,
processMarkdownEnvelope,
Expand Down Expand Up @@ -149,13 +154,17 @@ export async function websiteNavigationExtras(
websiteNavigationDependency(project),
];

// the contents of anything before the head
const includeInHeader = [];

// Determine any sass bundles
const sassBundles: SassBundle[] = [websiteNavigationSassBundle()];

const searchDep = websiteSearchDependency(project, source);
if (searchDep) {
dependencies.push(searchDep);
dependencies.push(...searchDep);
sassBundles.push(websiteSearchSassBundle());
includeInHeader.push(websiteSearchIncludeInHeader(project));
}

// Check to see whether the navbar or sidebar have been disabled on this page
Expand Down Expand Up @@ -223,6 +232,7 @@ export async function websiteNavigationExtras(

// return extras with bodyEnvelope
return {
[kIncludeInHeader]: includeInHeader,
[kTocTitle]: !hasTableOfContentsTitle(flags, format) &&
format.metadata[kTocFloat] !== false
? "On this page"
Expand Down Expand Up @@ -539,8 +549,10 @@ async function sidebarEjsData(project: ProjectContext, sidebar: Sidebar) {
// ensure title and search are present
sidebar.title = sidebarTitle(sidebar, project) as string | undefined;
sidebar.logo = resolveLogo(sidebar.logo);
sidebar.search = websiteSearch(project) === "sidebar"
? sidebar.search

const searchOpts = searchOptions(project);
sidebar.search = searchOpts && searchOpts.location === "sidebar"
? searchOpts.type
: false;

// ensure collapse & alignment are defaulted
Expand Down Expand Up @@ -759,15 +771,19 @@ async function navbarEjsData(
navbar: Navbar,
): Promise<Navbar> {
const collapse = navbar.collapse !== undefined ? !!navbar.collapse : true;

const searchOpts = searchOptions(project);

const data: Navbar = {
...navbar,
search: websiteSearch(project) === "navbar" ? navbar.search : false,
search: searchOpts && searchOpts.location === "navbar"
? searchOpts.type
: false,
background: navbar.background || "primary",
logo: resolveLogo(navbar.logo),
collapse,
[kCollapseBelow]: !collapse
? ""
: ("-" + (navbar[kCollapseBelow] || "lg")) as LayoutBreak,
[kCollapseBelow]: !collapse ? ""
: ("-" + (navbar[kCollapseBelow] || "lg")) as LayoutBreak,
pinned: navbar.pinned !== undefined ? !!navbar.pinned : false,
};

Expand Down

0 comments on commit e4a9521

Please sign in to comment.