pngwn / MDsveX

A markdown preprocessor for Svelte.
https://mdsvex.pngwn.io
MIT License
2.28k stars 96 forks source link

Can't use <svelte:head> in mdsvex file #55

Closed kevmodrome closed 4 years ago

kevmodrome commented 4 years ago

Currently trying to add some OG tags to my pages and running into an issue. Using the following code:

<svelte:head>
  <meta property="og:title" content={title} />
  <meta property="og:type" content="article" />
  <meta property="og:url" content="{host}{path}" />
</svelte:head>

I get the following error:

<svelte:head> tags cannot be inside elements or blocks
13: <Layout_MDSVEX_DEFAULT {...metadata}>
14: 
15: <svelte:head>
    ^
16:   <meta property="og:title" content={title} />
17:   <meta property="og:type" content="article" />
kevmodrome commented 4 years ago

Just realized I can probably put this in the frontmatter and stick it in the layout. Investigating.

pngwn commented 4 years ago

I need to fix this anyway. It is a limitation of the special tag parser that I just didn’t consider. Will be fixed in the next beta release.

m4rrc0 commented 4 years ago

Just a note for reference maybe. I use an intermediate SEO component and it is working. For example:

---
title: 'A title'
---
```js exec
import SEO from '../components/SEO';

<SEO lang="en" title="{_metadata.title}" description="A description" canonicalUrl="https://www.example.com/" />


The only problem I get is it renders an empty `<p>`.

I can even do
```jsx
<SEO><meta property='' content='' /></SEO>

So I guess you could just create a component

<svelte:head><slot></svelte:head>

Again, the only thing to pay attention to is we can't do

<SEO>
  <meta property='' content='' />
</SEO>

because it inserts a <p>

Any way to avoid that @pngwn ? Do you want me to create another issue? -> might be related to #21

pngwn commented 4 years ago

You can try this with the current beta which will be released as soon as find any time at all to work on it. The handling of various things has changed and could result in different behaviour.

If this is still present in the beta then please open a new issue. Thanks!

ninest commented 4 years ago

@pngwn Is there an ETA for when the next beta will be released?

Also, is it just me or is the demo site not working? The result tab is always empty

pngwn commented 4 years ago

Correct, it isn’t working.

I am genuinely sorry this hasn’t been released yet, I have been meaning to get around to it but in between relocating, starting a new job, and the zombie apocalypse descending, I just haven’t found the time. I’ll try to get this out either over the weekend or next week sometime. There will be a new site with better docs and a new (working) Playground.

pngwn commented 4 years ago

@themindstorm A new beta version has been released and this issue should be fixed.

kevmodrome commented 4 years ago

Closing this since it's fixed 👍