caressofsteel / hugo-story

A (modular, highly tweakable) responsive one-page Hugo template.
Other
215 stars 74 forks source link

Inserting HTML into items #15

Open austinj opened 3 years ago

austinj commented 3 years ago

I'm attempting to insert a link into the text for an Items element using HTML, but Hugo fails to build the page and throws this error: "failed to load data: "/Users/austinj/Documents/GitHub/retract/data/items.yml:23:1": failed to unmarshal YAML: yaml: line 23: did not find expected key". Line 23 is where I've done the following:

- name : "Title here" content : "Content here and here is a <a href="https://www.github.com">link</a>." style : "solid style2 major fa-cog"

Is there a way to add a link into the text of an item element?

caressofsteel commented 3 years ago

Have you tried formatting the link using markdown instead of HTML? I would also try escaping the double quotation marks in the URL.

austinj commented 3 years ago

Yeah, I've tried both. In yml, you just use a backslash to escape, right? Like <a href = \"https://www.google.com\">link. Neither is working so far.

On Thu, Apr 8, 2021 at 7:26 AM ⚔️ DR ⚔️ @.***> wrote:

Have you tried formatting the link using markdown instead of HTML? I would also try escaping the double quotation marks in the URL.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/caressofsteel/hugo-story/issues/15#issuecomment-815868821, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOE5YQRWLC2ECDTTEFY4STTHW4JNANCNFSM42RMBERQ .

caressofsteel commented 3 years ago

Ok. When I have some time I'll look into it. Thanks for the report.

georgeblck commented 3 years ago

What worked for me was saving the following html-code as layouts/partials/item.html

<section>
    <span class="icon {{ .style }}"></span>
    <h3>{{ .name }}</h3>
    {{ with .content }}<p>{{ . | safeHTML }}</p>{{ end }}
</section>

That way html syntax in the content field of each item is parsed correctly

JHenneberg commented 2 years ago

you can do it with pure markdown, but for this you need to adjsut the template. Just change safeHTML with markdownify: https://github.com/caressofsteel/hugo-story/blob/21dd26dda2b0927c2594e9fefd5e527dace6ff46/layouts/partials/banner.html#L6

actually it should work what you are trying to do. Somethin like <h1>Smth</h1> is working wiht safeHTML

Edit: I just tried it and it is working: <a href="https://www.google.de">sowas</a> results in no error but a beatiful clickable link (safeHTML on of course not markdownify)