roxiness / routify

Automated Svelte routes
https://routify.dev
1.85k stars 86 forks source link

v3: Inlined meta doesn't work for index files #538

Closed MarvinMiles closed 5 months ago

MarvinMiles commented 6 months ago

Describe the bug

For example: I have a route folder posts with two files: index.md and article.md inside. Adding inlinined meta works only for article.md. Trying to get meta from index.md returns empty object.

<!-- routify:meta _test="test" -->

Reproduction

Create route folder posts with two files: index.svelte and article.svelte inside. Then write <!-- routify:meta _test="test" --> inside those files and try to get this data on each route.

Logs

No response

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (16) x64 AMD Ryzen 7 5700U with Radeon Graphics
    Memory: 7.95 GB / 15.33 GB
  Binaries:
    Node: 16.20.2 - C:\Program Files\nodejs\node.EXE
    npm: 8.19.4 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    @roxi/routify: ^3.0.0-next.199 => 3.0.0-next.199
    svelte: ^3.59.1 => 3.59.2
    vite: ^4.3.9 => 4.4.9
jakobrosenberg commented 6 months ago

I'm unable to replicate this on 3.0.0-next.199 and 3.0.0-next.205.

In my src/routes/posts/index.md:

<!-- routify:meta _test="test" -->

<script>
    import {node, meta} from '@roxi/routify'
    export let context
</script>

{$meta._test}
{$node.meta._test}
{context.node.meta._test}

This prints test test test


Are you by any chance trying to get the index meta data from the posts folder? If so, _module.svelte|md represents the folder.

MarvinMiles commented 5 months ago

@jakobrosenberg Thanks. Got you... almost.

So how can I get meta data of active route inside _module.svelte file?

Got a working solution by $activeRoute.fragments[$activeRoute.fragments.length-1].node.meta, but this looks ugly and overheady.

Use case would be managing <svelte:head> inside _module file.

For example:

<svelte:head>
  <title>{ $activeNode.title }</title>
  <meta content="{ $activeNode.meta.description }" name="description" />
</svelte:head>
MarvinMiles commented 5 months ago

Ok $activeRoute.meta solves the issue.

Yet how can I get title (file name) of activeRoute?

jakobrosenberg commented 5 months ago

@MarvinMiles, assuming you mean the file name of the leaf component, you can try

$activeRoute.leaf.node.file