Skip to content

Commit

Permalink
feat(website): Add root files to routing table
Browse files Browse the repository at this point in the history
- Added logic to add markdown files with names "index.md" or "readme.md" to the routing table.
- Updated the routing table with the appropriate file paths.

fix(pages): Update getStaticPaths function

- Fixed an issue where an empty path was not handled correctly in the getStaticPaths function.
- Updated the code to handle empty paths properly.

chore(pages): Remove index.astro file

- Removed the unused index.astro file from the project.
  • Loading branch information
SakuraIsayeki committed Aug 12, 2023
1 parent 879c701 commit cc8a927
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 49 deletions.
11 changes: 11 additions & 0 deletions nodsoft_moltenobsidian_ssg_client/manifest-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@ export class VaultManifestClient {

private buildRoutingTable() {
const routingTable = new Map<string, VaultFile>();

for (const file of this.Manifest.files) {
// If markdown, add to routing table
console.log(file.path.split('/'));

const fileName = file.path.split('/').pop();

if (fileName?.toLowerCase() === 'index.md' || fileName?.toLowerCase() === 'readme.md') {
console.log(file.path.replace(/index\.md|readme\.md$/i, ''))

routingTable.set(file.path.replace(/index\.md|readme\.md$/i, '') ?? '/', file);
}

if (file.path.endsWith('.md')) {
const mdRegex = /\.md$/;
routingTable.set(file.path.replace(mdRegex, ''), file);
Expand Down
8 changes: 5 additions & 3 deletions nodsoft_moltenobsidian_web/src/pages/[...path].astro
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function toRelativeVaultPath(path) {
export async function getStaticPaths() {
const paths = [];
for (const path of manifestClient.routingTable.keys()) {
for (const path of manifestClient.routingTable.keys()) {
const ssgPath = new URL(toRelativeVaultPath(manifestClient.getAssetPath(path)), import.meta.url);
const frontMatterPath = new URL(manifestClient.getFrontMatterFilePath(toRelativeVaultPath(manifestClient.getAssetPath(path))), import.meta.url);
Expand All @@ -27,14 +27,15 @@ export async function getStaticPaths() {
if (frontMatter.obsidian?.publish === false || frontMatter.moltenobsidian?.publish === false) continue;
paths.push({
params: {path: path},
params: {path: path === '' ? undefined : path},
props: {
content: content,
...frontMatter
}
});
}
console.log(paths);
return paths;
}
Expand All @@ -43,7 +44,8 @@ const { content, cssclasses } = Astro.props;
---

<Layout>
<h1>Path: {path ?? "undefined"}</h1>
<code>Path: {path ?? "undefined"}</code>
<hr style="margin: 3rem;" />

<article class:list={cssclasses}>
<Fragment set:html={content} />
Expand Down
46 changes: 0 additions & 46 deletions nodsoft_moltenobsidian_web/src/pages/index.astro

This file was deleted.

0 comments on commit cc8a927

Please sign in to comment.