~dmbaturin/soupault

1

Specify Where to Insert HTML

Details
Message ID
<MlOb7hH--3-2@tutanota.de>
DKIM signature
pass
Download raw message
Hello and thank you for creating a splendid tool.

I'm trying to create an SEO plugin and have based it off of this plugin https://github.com/ryanartecona/ryanartecona.github.io/blob/develop/plugins/post-template.lua.

seo_block_elem = HTML.select_one(page, "seo")
or HTML.select_one(page, "div.seo")
if not seo_block_elem then
Plugin.fail("Couldn't find an SEO Block")
else
seo_block = HTML.inner_html(seo_block_elem)
end

-- move tags to the right place, and delete its previous location
seo_block_target = HTML.select_one(page, "head")
HTML.insert_after("title")(seo_block_target, HTML.parse(seo_block))
if
seo_block_elem
then
HTML.delete(seo_block_elem)
end

When I move content up to the head I can place it in the beginning or end, but I'm not certain how to place it after the <title>Title</title>.

Thank you,
Amy
Details
Message ID
<43161c29-0ae8-d230-7ade-f4c2da42bcb5@baturin.org>
In-Reply-To
<MlOb7hH--3-2@tutanota.de> (view parent)
DKIM signature
pass
Download raw message
Hi Amy,

The HTML.insert_after accepts an element reference as an argument rather
than a tag name (so that you can insert something after any identifiable
element rather than just the first one with specific tag name).
You need to select the element you want to insert something after, then
pass it to that function.

Example:

title_elem = HTML.select_one(page, "head title")
HTML.insert_after(title_elem, some_other_elem)

Let me know if it works for you. You can also attach the complete plugin
source so that I can give more specific advice.

On 10/7/21 2:16 PM, arashi@tutanota.de wrote:
> Hello and thank you for creating a splendid tool.
>
> I'm trying to create an SEO plugin and have based it off of this plugin https://github.com/ryanartecona/ryanartecona.github.io/blob/develop/plugins/post-template.lua.
>
> seo_block_elem = HTML.select_one(page, "seo")
> or HTML.select_one(page, "div.seo")
> if not seo_block_elem then
> Plugin.fail("Couldn't find an SEO Block")
> else
> seo_block = HTML.inner_html(seo_block_elem)
> end
>
> -- move tags to the right place, and delete its previous location
> seo_block_target = HTML.select_one(page, "head")
> HTML.insert_after("title")(seo_block_target, HTML.parse(seo_block))
> if
> seo_block_elem
> then
> HTML.delete(seo_block_elem)
> end
>
> When I move content up to the head I can place it in the beginning or end, but I'm not certain how to place it after the <title>Title</title>.
>
> Thank you,
> Amy 
Reply to thread Export thread (mbox)