~adnano/kiln-discuss

8 2

Adding content to feeds

Details
Message ID
<c66331d8-986f-eca1-1978-6d4ed68cefe3@ianmjones.com>
DKIM signature
missing
Download raw message
Hi,

I would like to include content in my feeds.

The current atom.xml template created by default by kiln at 
templates/_default/atom.xml does not include a <content> elements in 
each <entry>.

I'm struggling to get something working as just adding something like 
the following to the atom.xml template ends up with gmi content rather 
than HTML content as required by most feed readers.

<content>{{ .Content }}</content>

I've tried adding the following to the HTML output task I have in my 
config.toml...

[[tasks]]
input = [".gmi"]
output = ".html"
template = ".gmi"
preprocess.gmi = "gmnitohtml" ### <-new thing for feed
postprocess = "gmnitohtml -t html.tmpl"
static_dir = "static"
output_dir = "public.html"

...but as expected this results in double encoded HTML output, although 
the feed looks ok.

I'm needing to run the postprocess because I want to use an HTML 
template for final output that includes a <head> element etc.

Has anyone got their feed files to include properly formatted HTML 
content in each entry?

Is there a way of calling out to gmnitohtml from withing the atom.xml 
template itself?

Otherwise, do you think we need something like a preprocess_feed config 
item which then gets processed on the feed entries before or during the 
feed template processing?

Thanks,

Ian
Details
Message ID
<CBK4HIN3NSQD.106T5DAF1BFSL@nitro>
In-Reply-To
<c66331d8-986f-eca1-1978-6d4ed68cefe3@ianmjones.com> (view parent)
DKIM signature
pass
Download raw message
On Sat May 22, 2021 at 6:10 PM EDT, Ian M. Jones wrote:
> Hi,
>
> I would like to include content in my feeds.
>
> The current atom.xml template created by default by kiln at
> templates/_default/atom.xml does not include a <content> elements in
> each <entry>.
>
> I'm struggling to get something working as just adding something like
> the following to the atom.xml template ends up with gmi content rather
> than HTML content as required by most feed readers.
>
> <content>{{ .Content }}</content>
>
> I've tried adding the following to the HTML output task I have in my
> config.toml...
>
> [[tasks]]
> input = [".gmi"]
> output = ".html"
> template = ".gmi"
> preprocess.gmi = "gmnitohtml" ### <-new thing for feed
> postprocess = "gmnitohtml -t html.tmpl"
> static_dir = "static"
> output_dir = "public.html"
>
> ...but as expected this results in double encoded HTML output, although
> the feed looks ok.
>
> I'm needing to run the postprocess because I want to use an HTML
> template for final output that includes a <head> element etc.
>
> Has anyone got their feed files to include properly formatted HTML
> content in each entry?

Not that I know of.

> Is there a way of calling out to gmnitohtml from withing the atom.xml
> template itself?

No, but I might consider adding a function to execute external commands
from within templates. That seems like a useful feature.

> Otherwise, do you think we need something like a preprocess_feed config
> item which then gets processed on the feed entries before or during the
> feed template processing?

A better solution might be to use kiln's built-in template support for
the HTML template (instead of gmnitohtml's limited template support).
This way the postprocess command would be unnecessary. However, you will
have to create HTML variants of your existing Gemini templates.

If you don't want to maintain two versions of your templates, it seems
like adding a function to execute external commands would be the best
approach.
Details
Message ID
<de28fe69-f745-cc8b-d366-0c827f1b979e@ianmjones.com>
In-Reply-To
<CBK4HIN3NSQD.106T5DAF1BFSL@nitro> (view parent)
DKIM signature
missing
Download raw message
Thanks Adnan

> If you don't want to maintain two versions of your templates, it seems
> like adding a function to execute external commands would be the best
> approach.

Yeah, I'd rather not duplicate all my templates if at all possible.

I did just have a thought though ... what if gmnitohtml had access to 
safeHTML in the templates?

That would mean I could preprocess to HTML, and then in the postprocess 
usage with a template it would skip double HTML conversion if the 
content bit was like...

<html>
[snip]
<body>
{{ .Content | safeHTML }}
</body>
</html>

Bit of a hack, but maybe adding safeHTML/URL etc to gmnitohtml would be 
handy for other reasons too?

Ian
Details
Message ID
<CBK6ZYHXFVNW.2GX9Z41PDYP20@nitro>
In-Reply-To
<de28fe69-f745-cc8b-d366-0c827f1b979e@ianmjones.com> (view parent)
DKIM signature
pass
Download raw message
On Sat May 22, 2021 at 6:47 PM EDT, Ian M. Jones wrote:
> Thanks Adnan
>
> > If you don't want to maintain two versions of your templates, it seems
> > like adding a function to execute external commands would be the best
> > approach.
>
> Yeah, I'd rather not duplicate all my templates if at all possible.
>
> I did just have a thought though ... what if gmnitohtml had access to
> safeHTML in the templates?
>
> That would mean I could preprocess to HTML, and then in the postprocess
> usage with a template it would skip double HTML conversion if the
> content bit was like...
>
> <html>
> [snip]
> <body>
> {{ .Content | safeHTML }}
> </body>
> </html>
>
> Bit of a hack, but maybe adding safeHTML/URL etc to gmnitohtml would be
> handy for other reasons too?
>
> Ian

While this could work, it would be an abuse of gmnitohtml, whose purpose
is solely to convert Gemini text to HTML. The templating support is
meant to be very basic for sites who only want to apply a single
template to all pages. So I would be reluctant to add support for this.

Also, I'm not sure it would work the way you think. Preprocessing the
text to HTML would mean that HTML would be provided to the Gemini text
templates, which is obviously incorrect. And that resulting Gemini text
with HTML in it would be provided to the postprocess gmnitohtml command.
To get the desired behavior you would have to write HTML templates
anyways.

I think I am instead going to add a command to execute external commands
from templates. It's the cleanest solution to the problem (other than
using HTML templates).
Details
Message ID
<CBK7HWBSGV4J.2QQ6DBJTTOT51@nitro>
In-Reply-To
<CBK6ZYHXFVNW.2GX9Z41PDYP20@nitro> (view parent)
DKIM signature
pass
Download raw message
I went ahead and added a function to execute external commands from
within templates. You can use it in your atom.xml template like so:

	<content>{{ exec "gmnitohtml" .Content | safeHTML }}</content>
Details
Message ID
<94d66ed3-1a6a-9bd9-299a-4abdc2ee37cc@ianmjones.com>
In-Reply-To
<CBK6ZYHXFVNW.2GX9Z41PDYP20@nitro> (view parent)
DKIM signature
missing
Download raw message
On 23/05/2021 01:18, Adnan Maolood wrote:
> On Sat May 22, 2021 at 6:47 PM EDT, Ian M. Jones wrote:
>>
>> I did just have a thought though ... what if gmnitohtml had access to
>> safeHTML in the templates?
>>
...
>> Bit of a hack, but maybe adding safeHTML/URL etc to gmnitohtml would be
>> handy for other reasons too?
>>
> 
> While this could work, it would be an abuse of gmnitohtml, whose purpose
> is solely to convert Gemini text to HTML. The templating support is
> meant to be very basic for sites who only want to apply a single
> template to all pages. So I would be reluctant to add support for this.

Yeah, didn't sit comfortably with me either, but thought I'd throw it 
out there.

> 
> Also, I'm not sure it would work the way you think. Preprocessing the
> text to HTML would mean that HTML would be provided to the Gemini text
> templates, which is obviously incorrect. And that resulting Gemini text
> with HTML in it would be provided to the postprocess gmnitohtml command.
> To get the desired behavior you would have to write HTML templates
> anyways.

Yeah, this occurred to me after I sent my message too. Also, it would 
mean the atom.xml created along with the gemini version of the site 
would still be incorrect (although I'm not sure it'd ever be discovered 
or used anyway).

> 
> I think I am instead going to add a command to execute external commands
> from templates. It's the cleanest solution to the problem (other than
> using HTML templates).
> 

Awesome!
Details
Message ID
<4ac48ea1-407c-66aa-0b05-4893f9426472@ianmjones.com>
In-Reply-To
<CBK7HWBSGV4J.2QQ6DBJTTOT51@nitro> (view parent)
DKIM signature
missing
Download raw message
On 23/05/2021 01:42, Adnan Maolood wrote:
> I went ahead and added a function to execute external commands from
> within templates. You can use it in your atom.xml template like so:
> 
> 	<content>{{ exec "gmnitohtml" .Content | safeHTML }}</content>
> 

Brilliant, thanks Adnan!

I've given it a whirl and it works very well, thank you.

I did need to do a little extra in the atom.xml template as the <br> 
tags created by gmnitohtml which are perfectly valid in most contexts, 
caused validations errors in this xml context.

I had to ensure they were self closing tags.

<content type="html">
     {{ with exec "gmnitohtml" .Content }}
     {{ exec "sed -e s/<br>/<br\\/>/g" . | safeHTML }}
     {{ end }}
</content>

That did the job.

Thanks again,

Ian
Details
Message ID
<CBKQLVJSI10G.KPBE9MPIO835@nitro>
In-Reply-To
<4ac48ea1-407c-66aa-0b05-4893f9426472@ianmjones.com> (view parent)
DKIM signature
pass
Download raw message
On Sun May 23, 2021 at 5:42 AM EDT, Ian M. Jones wrote:
> Brilliant, thanks Adnan!
>
> I've given it a whirl and it works very well, thank you.
>
> I did need to do a little extra in the atom.xml template as the <br>
> tags created by gmnitohtml which are perfectly valid in most contexts,
> caused validations errors in this xml context.
>
> I had to ensure they were self closing tags.

I updated gmnitohtml to use self-closing tags so the output is also
valid XML.
Details
Message ID
<f7dda958-746e-92d5-3909-ca8ac56554b6@ianmjones.com>
In-Reply-To
<CBKQLVJSI10G.KPBE9MPIO835@nitro> (view parent)
DKIM signature
missing
Download raw message
On 23/05/2021 16:40, Adnan Maolood wrote:
> 
> I updated gmnitohtml to use self-closing tags so the output is also
> valid XML.
> 

Nice one, thank you.
Reply to thread Export thread (mbox)