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
6 changes: 4 additions & 2 deletions Source/SuperOffice.DocsNext/ClientApp/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { rehypeHeadingIds } from "@astrojs/markdown-remark";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import remarkIncludeDirective from "./src/plugins/AddIncludesToMarkdown.js";
import remarkRestyleDirective from "./src/plugins/RestyleDirectives.js";
import remarkFixRelativeLinks from "./src/plugins/FixMarkdownLinks.js"
import react from "@astrojs/react";
import yaml from '@rollup/plugin-yaml';
import redirectFrom from "astro-redirect-from";
Expand All @@ -22,7 +23,8 @@ export default defineConfig({
],

markdown: {
remarkPlugins: [remarkDirective, codeImport, remarkIncludeDirective, remarkRestyleDirective],
remarkPlugins: [remarkDirective, codeImport, remarkIncludeDirective, remarkRestyleDirective, remarkFixRelativeLinks
],
rehypePlugins: [
rehypeHeadingIds,
[
Expand Down Expand Up @@ -123,5 +125,5 @@ export default defineConfig({
logLevel: process.env.CI ? 'error' : 'info',
site: "https://app-superoffice-docs-dev.azurewebsites.net/",
// base: "/",
// trailingSlash: "never",
// trailingSlash: "ignore",
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ interface Props {
class={`bg-white px-3 py-5 lg:m-0 duration-300 ease-in-out transition-shadow hover:shadow-[0_0px_8px_rgba(0,0,0,0.70)] min-h-full`}
>
<div class="grid grid-cols-1 gap-2 h-fit">
<a href={item.url && resolveRelativeFilePath(currentPath,item.url)} class="font-bold text-[17px]">{item.title}</a>
<a href={item.url && resolveRelativeFilePath(currentPath, item.url)} class="font-bold text-[17px]">{item.title}</a>
{
item.links?.map((subitem) => {
return (
<div class="flex flex-col items-center pb-1">
<a
class="w-full hover:underline text-superOfficeGreen"
href={subitem.url}
href={resolveRelativeFilePath(currentPath, subitem.url)}
>
{subitem.text}
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default function TableOfContentList({
// console.warn(`[generatePath] Missing href/topicHref for TOC item:`, item);
return "#";
}
const formattedURL = `${slug}/${trimFileExtension(rawPath)}`.replace("/index", "")
const formattedURL = `${slug}/${trimFileExtension(rawPath)}`.replace("/index", "/")
const resolvedPath = new URL(formattedURL, "http://docs.superoffice.com").pathname;
return resolvedPath;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { visit } from 'unist-util-visit';

/**
* Fix Markdown links and definitions that end with `.md` or `/index.md`
*/
export default function remarkFixMarkdownLinks() {
return (tree) => {
// Handle both inline links and reference definitions
visit(tree, ['link', 'definition'], (node) => {
if (!node.url || typeof node.url !== 'string') return;

let url = node.url.trim();

// Skip external and anchor links
if (url.startsWith('http') || url.startsWith('#')) return;

// Remove trailing /index.md
url = url.replace(/\/index\.md(?=$|[?#])/i, '/');

// Remove trailing .md
url = url.replace(/\.md$/i, '');

node.url = url;
});
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ export default function remarkRestyleDirective() {

if (remainingText) {
textNode.value = remainingText;
contentChildren = para.children;
contentChildren = node.children;
} else {
contentChildren = para.children.slice(1);
// Remove first paragraph if it only contained the directive
contentChildren = node.children.slice(1);
}

node.type = 'parent';
Expand Down
4 changes: 2 additions & 2 deletions Source/SuperOffice.DocsNext/ClientApp/src/utils/slugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const contentRepo = "superoffice-docs"; // primary content repository
*/
export function stripFilePathAndExtension(filePath: string, collection: string): string {
const base = `${contentDir}/`
return filePath.replace(base, "").replace(`${collection}/`, "").replace(/\/index/g, "").replace(/\.(md|yml|yaml)$/g, "");;
return filePath.replace(base, "").replace(`${collection}/`, "").replace(/\/index/g, "/").replace(/\.(md|yml|yaml)$/g, "");;
}

/**
Expand Down Expand Up @@ -154,6 +154,6 @@ export function resolveRelativeFilePath(currentPath: string, filepath: string):
return filepath
}

return `${currentPath.split("/").pop()?.replace(/\.html$/, "")}/${trimFileExtension(filepath).replace(/\/index$/, "")}`
return `${currentPath.split("/").filter(Boolean).pop()?.replace(/\.html$/, "")}/${trimFileExtension(filepath).replace(/\/index$/, "/")}`

}
1 change: 1 addition & 0 deletions Source/SuperOffice.DocsNext/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
// Redirect /something.html -> /something (permanent redirect)
.AddRedirect(@"^(.*)\.html$", "$1", statusCode: 301)
.AddRewrite(@"^$", "index.html", skipRemainingRules: true)
.AddRewrite(@"^(.*)/$", "$1.html", skipRemainingRules: true)
// Rewrite /something -> /something.html (internal rewrite)
// But avoids rewriting known static file types
.AddRewrite(@"^(?!.*\.(?:js|css|png|jpg|jpeg|gif|svg|ico|json|txt|xml|map)$)(.*)$", "$1.html", skipRemainingRules: true);
Expand Down