Skip to content

Commit

Permalink
use generic git icon for non-github repo urls
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Apr 14, 2022
1 parent a0027d7 commit 73a6e3f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 51 deletions.
6 changes: 3 additions & 3 deletions src/project/types/book/book-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
import { kProjectRender, ProjectConfig } from "../../types.ts";

import {
isGithubRepoUrl,
kBodyFooter,
kBodyHeader,
kContents,
Expand All @@ -53,6 +52,7 @@ import {
kSiteUrl,
kTwitterCard,
kWebsite,
repoUrlIcon,
websiteConfigActions,
websiteProjectConfig,
} from "../website/website-config.ts";
Expand Down Expand Up @@ -186,11 +186,11 @@ export async function bookProjectConfig(

// if we have tools then fold those into the sidebar

// Prorcess the repo-url (github or journal-code) and other
// code tools
const tools = [];
if (site[kSiteRepoUrl]) {
const repoUrl = site[kSiteRepoUrl] as string;
const icon = isGithubRepoUrl(repoUrl) ? "github" : "journal-code";
const icon = repoUrlIcon(repoUrl);
tools.push({
text: "Source Code",
icon,
Expand Down
10 changes: 6 additions & 4 deletions src/project/types/website/website-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,12 @@ export function websiteMetadataFields(): Array<string | RegExp> {
return [kWebsite, "site"];
}

export function isGithubRepoUrl(_url: string): boolean {
// always validate `true` to account for GH enterprise
// (see https://github.com/quarto-dev/quarto-cli/issues/421)
return true;
export function repoUrlIcon(url: string): string {
if (url.indexOf("github.com") !== -1) {
return "github";
} else {
return "git";
}
}

export function websiteConfigActions(
Expand Down
84 changes: 40 additions & 44 deletions src/project/types/website/website-navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ import {
} from "./website-search.ts";

import {
isGithubRepoUrl,
kSiteNavbar,
kSiteReaderMode,
kSiteRepoActions,
kSiteRepoUrl,
kSiteSidebar,
kWebsite,
repoUrlIcon,
websiteConfigActions,
websiteConfigBoolean,
websiteHtmlFormat,
Expand Down Expand Up @@ -540,51 +540,47 @@ function handleRepoLinks(
if (repoActions.length > 0 || elRepoSource) {
const repoInfo = websiteRepoInfo(config);
if (repoInfo) {
if (isGithubRepoUrl(repoInfo.baseUrl)) {
if (repoActions.length > 0) {
// find the toc
const toc = doc.querySelector(`nav[role="doc-toc"]`);
if (toc) {
// get the action links
const links = repoActionLinks(
repoActions,
repoInfo,
websiteRepoBranch(config),
source,
language,
);
const actionsDiv = doc.createElement("div");
actionsDiv.classList.add("toc-actions");
const iconDiv = doc.createElement("div");
const iconEl = doc.createElement("i");
iconEl.classList.add("bi").add("bi-github");
iconDiv.appendChild(iconEl);
actionsDiv.appendChild(iconDiv);
const linksDiv = doc.createElement("div");
linksDiv.classList.add("action-links");
links.forEach((link) => {
const a = doc.createElement("a");
a.setAttribute("href", link.url);
a.classList.add("toc-action");
a.innerHTML = link.text;
const p = doc.createElement("p");
p.appendChild(a);
linksDiv.appendChild(p);
});
actionsDiv.appendChild(linksDiv);
toc.appendChild(actionsDiv);
}
}
if (elRepoSource) {
elRepoSource.setAttribute(
kDataQuartoSourceUrl,
`${repoInfo.baseUrl}blob/${
websiteRepoBranch(config)
}/${repoInfo.path}${source}`,
if (repoActions.length > 0) {
// find the toc
const toc = doc.querySelector(`nav[role="doc-toc"]`);
if (toc) {
// get the action links
const links = repoActionLinks(
repoActions,
repoInfo,
websiteRepoBranch(config),
source,
language,
);
const actionsDiv = doc.createElement("div");
actionsDiv.classList.add("toc-actions");
const iconDiv = doc.createElement("div");
const iconEl = doc.createElement("i");
iconEl.classList.add("bi").add("bi-" + repoUrlIcon(repoInfo.baseUrl));
iconDiv.appendChild(iconEl);
actionsDiv.appendChild(iconDiv);
const linksDiv = doc.createElement("div");
linksDiv.classList.add("action-links");
links.forEach((link) => {
const a = doc.createElement("a");
a.setAttribute("href", link.url);
a.classList.add("toc-action");
a.innerHTML = link.text;
const p = doc.createElement("p");
p.appendChild(a);
linksDiv.appendChild(p);
});
actionsDiv.appendChild(linksDiv);
toc.appendChild(actionsDiv);
}
} else {
warnOnce(`Repository links require a github.com ${kSiteRepoUrl}`);
}
if (elRepoSource) {
elRepoSource.setAttribute(
kDataQuartoSourceUrl,
`${repoInfo.baseUrl}blob/${
websiteRepoBranch(config)
}/${repoInfo.path}${source}`,
);
}
} else {
warnOnce(
Expand Down

0 comments on commit 73a6e3f

Please sign in to comment.