Skip to content

Commit

Permalink
Update base path base config
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesLoder committed Dec 1, 2024
1 parent a0575fd commit fa59ce1
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 13 deletions.
18 changes: 8 additions & 10 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import starlight from "@astrojs/starlight";
import { defineConfig } from "astro/config";
import starlightTypeDoc, { typeDocSidebarGroup } from "starlight-typedoc";
import { remarkBasePath } from "./prepend_base_path.js";

const basePath = process.env.NODE_ENV === "production" ? "/hebrew-transliteration" : "/";

// https://astro.build/config
export default defineConfig({
Expand All @@ -12,24 +15,19 @@ export default defineConfig({
build: {
assets: "assets"
},
base: process.env.NODE_ENV === "production" ? "/hebrew-transliteration" : "/",
base: basePath,
markdown: {
remarkPlugins: [[remarkBasePath, { base: basePath }]]
},
redirects: {
"/": {
status: 302,
destination: `/getting-started/quick-start`
destination: `${basePath}/getting-started/quick-start`
}
},
integrations: [
starlight({
title: `hebrew-transliteration v${process.env.npm_package_version || ""}`,
head: [
{
tag: "base",
attrs: {
href: process.env.NODE_ENV === "production" ? "/hebrew-transliteration/" : "/"
}
}
],
plugins: [
starlightTypeDoc({
entryPoints: ["./src/index.ts"],
Expand Down
71 changes: 71 additions & 0 deletions docs/prepend_base_path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// @ts-check
import { CONTINUE, visit } from "unist-util-visit";

/**
* Check if url is absolute
*
* @param {string} url
* @returns {boolean}
*/
function isAbsoluteUrl(url) {
return url.startsWith("http://") || url.startsWith("https://");
}

/**
* Check if url is a heading link
*
* @param {string} url
*/
function isHeadingLink(url) {
return url.startsWith("#");
}

/**
* Check if node is a link node
*
*/
function isLinkNode(node) {
return node.type === "link" && !!node.url;
}

/**
* Check if url starts with base path
*
* @param {string} str
* @param {string} base
*/
function startsWithBasePath(str, base) {
return str.startsWith(base);
}

export function remarkBasePath(options = {}) {
const { base = "" } = options;

return (tree) => {
visit(tree, (node) => {
// Handle link nodes
if (isLinkNode(node)) {
if (!isAbsoluteUrl(node.url) && !isHeadingLink(node.url) && !startsWithBasePath(node.url, base)) {
node.url = `${base}${node.url}`;
}
return CONTINUE;
}

const hasHref = node?.attributes?.find((a) => a.name === "href");
if (hasHref) {
node.attributes = node.attributes.map((a) => {
if (
a.name === "href" &&
!isAbsoluteUrl(a.value) &&
!isHeadingLink(a.value) &&
!startsWithBasePath(a.value, base)
) {
a.value = `${base}${a.value}`;
return a;
}
return a;
});
}
});
};
}
12 changes: 9 additions & 3 deletions docs/src/content/docs/getting-started/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@ Use it live at [https://hebrewtransliteration.app](https://hebrewtransliteration

This package contains 3 functions for:

<LinkCard title="Transliteration" href="api/functions/transliterate" description="Create customized transliterations" />
<LinkCard title="Removing Niqqud" href="api/functions/remove" description="Remove accent marks and vowel points" />
<LinkCard
title="Transliteration"
href="/api/functions/transliterate"
description="Create customized transliterations"
/>
<LinkCard title="Removing Niqqud" href="/api/functions/remove" description="Remove accent marks and vowel points" />
<LinkCard
title="Sequencing Text"
href="api/functions/sequence"
href="/api/functions/sequence"
description="Sequence characters according to the SBL Hebrew font manual"
/>

Another [link](/api/functions/transliterate)

0 comments on commit fa59ce1

Please sign in to comment.