Search code examples
ghost-blogghost

Ghost any way to factorize HTML patterns?


my title isn't brilliant, but I don't know exactly how to put it, I lack some knowledge. If you have a better title, please let me know :)

But the question is simple. Let me tell you the story. I blog with Ghost, and as most of us, I put some images in my blog.

I don't use the native way to insert images in my blog, aka:

![Ghost Logos](https://ghost.org/assets/logos.png)

Doing it this way is too restrictive, it doesn't allow you to add a caption or to change the image width. Instead, I write the HTML directly, and it looks like that:

<figure>
<img src="https://ghost.org/assets/logos.png" alt="Ghost Logos" width="80%"/>
<figcaption>Here come the logos</figcaption>
</figure>

And it works great! My only concern is that I have to copy/paste this all the time, which a little bit tedious.

So I was wondering if there is any way to, say, define a kind of function or macro or whatever, so that I just have to call it with some arguments (image source, width, caption), and it's automatically replaced by the HTML.

I know there are plenty of technologies under the hood of Ghost (Markdown, Handlebars, and probably much more), and that it can do a lot of magic. But I don't know ho to invoke it...

So if you're this kind of wizard and know a way to achieve that, please let me know :)


Solution

  • Before apps come along I don't really see this being possible within Ghost.

    Until then I would suggest using some extension for the browser, either a Macro extension or something like Auto Text Expander which allows you to define your own shortcuts. You could for example use the following as an expansion for your figure-element:

    Input: !!

    Output:

    <figure>
        <img src="<!--?atec?-->" alt="">
        <figcaption>Caption</figcaption>
    </figure>