Gemini to HTML generator
hi, i was wondering if there are any reliable projects that i could use to convert my capsule with gemlogs into html with css automatically? i got a physical server and will be transfering my stuff onto it, so i decided to give a common web a try as well. as web is inferior to gemini and hand-editing it absolutely sucks, i'd prefer to still write my posts in gemtext for my capsule, and then pass them through some soft that either converts them once or acts as a proxy to web
the only hard requirements is for it to have some css so i could style it somehow
any recommendations?
May 04 · 2 months ago
16 Comments ↓
I know it is posible because I seen it before pages made automaticaly from a gemini, but i can't remember the name of the program they use and also, can't find the blog who made the tutorial...
i woud just use kineto to proxy content to http world. afaik it allows to specify custom css.
🚀 clseibold · May 04 at 08:23:
Oh, writing a gemini to html converter is very easy to do.
I'm sure there is some converter that is already available, but I don't know of any off the top of my head, aside from what the HTTP to Gemini proxies use. But just in case there isn't, I'll describe how it's done below very generally. As a sidenote, you don't need any special CSS classes to attach CSS to this stuff. Just use *tag selectors.*
All of the line types in Gemini have HTML equivalents (whereas the vice versa of course is not true). Parse your gemtext by line, and turn headings into
-, blockquotes into , links into (or - links need to be block elements, but this can instead be handled in CSS if you want).Then you just need to handle list items, which are slightly more complicated only because you need to wrap your entire list with
. But to do this, the first list line that follows a non-list line you see will use - text
, then do all the other list items if they are available with just - , and at the list item line that precedes a non-list line, which is the end of your list, add on the closing
Preformatted blocks should translate to
and
, iirc. And I think that's pretty much everything. All the other lines should be Lastly, prepend the HTML heading part (`
`) and append the footer part (``) to your HTML string you are constructing.CSS can be done by just using tag selectors - you can just style specific tags. If you wanted, you can add to the CSS `a { display: block; }` so that links are always blocks without having to wrap them in paragraph tags.
The only other CSS thing you might want to do is center the page on the screen (like what lagrange and profectus do to gemini pages - a maximum width page that's centered horizontally). I can't remember if you can do this with the body, but the other option is to just wrap the entire body in a div with an id (#wrapper) and then add this CSS: #wrapper { margin: auto; max-width: 600px; }
This extra CSS stuff can be inline, so you can just place it right in the
section that you are prepending to your HTML string.I use the kineto proxy with a custom stylesheet. It was a bit difficult to get the line distance right for me but it's definitely doable with CSS.
— https://sr.ht/~sircmpwn/kineto/
I've put it behind my nginx reverse proxy, which is advised, but it's definitely a very easy way to get your Gemini content to the web.
🌲 byte [OP] · May 04 at 16:03:
@clseibold yeah that what i ended up doing for now, just styling the html tags :) also added a bit of functionality to inject headers and footers and have a classic menus this way
🚀 frecklemaster · May 04 at 16:32:
TBH+seems+like+a+simple+script.
🐦 roughnecks · May 05 at 05:59:
I tried loxy first, then september, then kineto. Always went back to loxy ¯\_(ツ)_/¯
I have written a Gemini to HTML converter (and I mentioned it in Usenet), although it does not use CSS at all (since I don't like CSS and I think the default styles are usually better anyways). (Maybe later I will copy it here too, since I have made a few changes since I put it on Usenet.)
Here's one simple implementation of gemtext -> HTML; no CSS, but that should be easy to hack in.
— gemini.thegonz.net/gmi2html.sed
There is also
— https://codeberg.org/snonux/gemtexter
👽 TKurtBond · May 06 at 01:55:
I use the static site generation feature of Lichen, a CMS written in Forth, to generate the HTML version of consp.org.
Lichen is at https://codeberg.org/stringbone/lichen/src/branch/master
👻 mediocregopher [...] · May 06 at 06:40:
If you happen to be using Caddy as your webserver, I wrote a plugin for it which can do what you want. There's an example of how to use it in the repo as well.
— https://dev.mediocregopher.com/mediocre-caddy-plugins/#httphandlersgemtext
🌲 byte [OP] · May 07 at 23:01:
@mediocregopher oh wow that's amazing! i should try that :3
Thought, I should use Markdown for preprocessing and then convert it separately to Gemtext, HTML, and any other format. I made a mistake when translated my existing documents from Markdown to Gemtext, just imho.
👻 mediocregopher [...] · May 08 at 07:16:
@byte feel free to email me if you have any questions about using it :)
🚀 clseibold · May 08 at 10:10:
@ps That seems like a good way to do it. Going from MD to another format will allow you to use more features that are HTML that get discarded in the gemtext. I wonder if anybody has done anything with AsciiDoc to HTML and Gemtext?
Source
, links into (or - links need to be block elements, but this can instead be handled in CSS if you want).Then you just need to handle list items, which are slightly more complicated only because you need to wrap your entire list with
. But to do this, the first list line that follows a non-list line you see will use
- text
, then do all the other list items if they are available with just- , and at the list item line that precedes a non-list line, which is the end of your list, add on the closing
Preformatted blocks should translate to
and, iirc. And I think that's pretty much everything. All the other lines should beLastly, prepend the HTML heading part (`
`) and append the footer part (``) to your HTML string you are constructing.CSS can be done by just using tag selectors - you can just style specific tags. If you wanted, you can add to the CSS `a { display: block; }` so that links are always blocks without having to wrap them in paragraph tags.
The only other CSS thing you might want to do is center the page on the screen (like what lagrange and profectus do to gemini pages - a maximum width page that's centered horizontally). I can't remember if you can do this with the body, but the other option is to just wrap the entire body in a div with an id (#wrapper) and then add this CSS: #wrapper { margin: auto; max-width: 600px; }
This extra CSS stuff can be inline, so you can just place it right in the
section that you are prepending to your HTML string.I use the kineto proxy with a custom stylesheet. It was a bit difficult to get the line distance right for me but it's definitely doable with CSS.
— https://sr.ht/~sircmpwn/kineto/
I've put it behind my nginx reverse proxy, which is advised, but it's definitely a very easy way to get your Gemini content to the web.
🌲 byte [OP] · May 04 at 16:03:
@clseibold yeah that what i ended up doing for now, just styling the html tags :) also added a bit of functionality to inject headers and footers and have a classic menus this way
🚀 frecklemaster · May 04 at 16:32:
TBH+seems+like+a+simple+script.
🐦 roughnecks · May 05 at 05:59:
I tried loxy first, then september, then kineto. Always went back to loxy ¯\_(ツ)_/¯
I have written a Gemini to HTML converter (and I mentioned it in Usenet), although it does not use CSS at all (since I don't like CSS and I think the default styles are usually better anyways). (Maybe later I will copy it here too, since I have made a few changes since I put it on Usenet.)
Here's one simple implementation of gemtext -> HTML; no CSS, but that should be easy to hack in.
— gemini.thegonz.net/gmi2html.sed
There is also
— https://codeberg.org/snonux/gemtexter
👽 TKurtBond · May 06 at 01:55:
I use the static site generation feature of Lichen, a CMS written in Forth, to generate the HTML version of consp.org.
Lichen is at https://codeberg.org/stringbone/lichen/src/branch/master
👻 mediocregopher [...] · May 06 at 06:40:
If you happen to be using Caddy as your webserver, I wrote a plugin for it which can do what you want. There's an example of how to use it in the repo as well.
— https://dev.mediocregopher.com/mediocre-caddy-plugins/#httphandlersgemtext
🌲 byte [OP] · May 07 at 23:01:
@mediocregopher oh wow that's amazing! i should try that :3
Thought, I should use Markdown for preprocessing and then convert it separately to Gemtext, HTML, and any other format. I made a mistake when translated my existing documents from Markdown to Gemtext, just imho.
👻 mediocregopher [...] · May 08 at 07:16:
@byte feel free to email me if you have any questions about using it :)
🚀 clseibold · May 08 at 10:10:
@ps That seems like a good way to do it. Going from MD to another format will allow you to use more features that are HTML that get discarded in the gemtext. I wonder if anybody has done anything with AsciiDoc to HTML and Gemtext?
Source