Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,92 @@ import { findDeclaration, realPackagesName } from "./manifest.mjs";

const packages = ["main", "fiori", "compat", "ai"];

/**
* Calculate the correct slug for a component based on its file path
* @param {string} filePath - Full path to the .mdx file
* @param {string} packageName - Package name (main, fiori, compat, ai)
* @param {string} componentName - Component name (filename without extension)
* @returns {string} - The calculated slug
*/
const calculateSlug = (filePath, packageName, componentName) => {
// Normalize path separators for cross-platform compatibility
const normalizedPath = filePath.replace(/\\/g, '/');

// Extract the path relative to _components_pages/<package>/
const packagePattern = new RegExp(`_components_pages/${packageName}/(.*)$`);
const match = normalizedPath.match(packagePattern);

if (!match) {
console.warn(`Warning: Could not extract relative path for ${filePath}`);
return null;
}

const relativeFromPackage = match[1];
const fileDir = path.dirname(relativeFromPackage);

// Determine depth:
// - "Component.mdx" (at package root) -> depth 0
// - "Component/Component.mdx" (in subdirectory) -> depth 1
const isInSubdirectory = fileDir !== '.';

if (packageName === "main") {
// Main package: URLs are /components/ComponentName
if (isInSubdirectory) {
// From main/Component/Component.mdx -> ../../Component
return `../../${componentName}`;
} else {
// From main/Component.mdx -> ../Component
return `../${componentName}`;
}
} else {
// Other packages (fiori, ai, compat): URLs are /components/<package>/ComponentName
if (isInSubdirectory) {
// From fiori/Component/Component.mdx -> ../Component
return `../${componentName}`;
} else {
// From fiori/Component.mdx -> ./Component
return `./${componentName}`;
}
}
};

/**
* Inject or update slug in frontmatter
* @param {string} fileContent - Original file content
* @param {string} slug - Calculated slug
* @returns {string} - Updated file content with correct slug
*/
const injectSlug = (fileContent, slug) => {
if (!slug) {
return fileContent;
}

// Check if frontmatter exists
const frontmatterMatch = fileContent.match(/^---\n([\s\S]*?)\n---/);

if (!frontmatterMatch) {
// No frontmatter - add it with slug
return `---\nslug: ${slug}\n---\n\n${fileContent}`;
}

const frontmatter = frontmatterMatch[1];
const slugMatch = frontmatter.match(/^slug:\s*(.+)$/m);

if (slugMatch) {
// Slug exists - replace it
const oldSlug = slugMatch[1].trim();
if (oldSlug !== slug) {
console.log(` Updating slug: ${oldSlug} -> ${slug}`);
}
const updatedFrontmatter = frontmatter.replace(/^slug:\s*(.+)$/m, `slug: ${slug}`);
return fileContent.replace(frontmatterMatch[0], `---\n${updatedFrontmatter}\n---`);
} else {
// Frontmatter exists but no slug - add slug
const updatedFrontmatter = `slug: ${slug}\n${frontmatter}`;
return fileContent.replace(frontmatterMatch[0], `---\n${updatedFrontmatter}\n---`);
}
};

const generateComponents = (source = "./docs/_components_pages", level = 1) => {
const sourcePath = path.resolve(source);
const targetPath = source.replace("_components_pages", "components");
Expand Down Expand Up @@ -44,9 +130,14 @@ const generateComponents = (source = "./docs/_components_pages", level = 1) => {
}

if (packageName) {
const fileContent = fs.readFileSync(path.join(sourcePath, file), { encoding: "utf-8" });
const filePath = path.join(sourcePath, file);
let fileContent = fs.readFileSync(filePath, { encoding: "utf-8" });
const declaration = findDeclaration({ package: realPackagesName(packageName), name: fileName })

// Calculate and inject correct slug
const calculatedSlug = calculateSlug(filePath, packageName, fileName);
fileContent = injectSlug(fileContent, calculatedSlug);

fs.writeFileSync(path.join(targetPath, `${fileName}.mdx`), parseComponentDeclaration(declaration, fileContent))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../Button
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../ButtonState
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../Table
---

import Basic from "../../../_samples/compat/Table/Basic/Basic.md";
import ActiveRows from "../../../_samples/compat/Table/ActiveRows/ActiveRows.md";
import Grouping from "../../../_samples/compat/Table/Grouping/Grouping.md";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../TableCell
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../TableColumn
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../TableGroupRow
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../TableRow
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../DynamicPage
---

import Basic from "../../../_samples/fiori/DynamicPage/Basic/Basic.md";

<%COMPONENT_OVERVIEW%>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../DynamicPageHeader
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../DynamicPageTitle
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../MediaGalleryItem
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../NotificationListGroupItem
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../NotificationListItem
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../ProductSwitchItem
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../SearchItem
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../SearchItemGroup
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../SearchMessageArea
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../SearchScope
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../ShellBarBranding
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../ShellBarItem
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../ShellBarSearch
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../ShellBarSpacer
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../SideNavigationGroup
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../SideNavigationItem
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../SideNavigationSubItem
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../TimelineGroupItem
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../TimelineItem
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
slug: ../UploadCollectionItem
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../UserMenu
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../UserMenuAccount
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../UserMenuItem
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../UserMenuItemGroup
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../UserSettingsAccountView
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../UserSettingsAppearanceView
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../UserSettingsAppearanceViewGroup
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../UserSettingsAppearanceViewItem
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../UserSettingsDialog
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../UserSettingsItem
sidebar_class_name: newComponentBadge
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
slug: ../UserSettingsView
sidebar_class_name: newComponentBadge
---

Expand Down
Loading
Loading