~dmbaturin/soupault

4 2

Two Beginner Questions

Jonah G
Details
Message ID
<CACAg5t4j8bPy8ZJJa_s2dFvRgUPORXseBSVB7JTwSw9xoZJ2Yg@mail.gmail.com>
DKIM signature
pass
Download raw message
Just started trying out soupault today and got it working, but have
two questions:

1. What if I have more than 1 "main template"?  Ie, some pages should
be embedded in template1, others in template2.  I know I could just
copy the full html for template2 for every page that requires it, but
that would be repetitive and unmaintainable.  What I want is way to
specify on the page: "This page should be embedded in this template".
Is there a way to achieve that?

2. Is it possible to select the content of an attribute rather than
the text content of the node.  Eg, say I want  the
`index_date_selector` to populate the `date` field with the value of
the attribute `time[datetime]`.  If I specify that as the selector, it
still selects "content" from `<time
datetime="2020-04-11">content</time>`.  I did find the example below,
but it doesn't seem exactly analogous.

```
selector = '*[class^="language-"]'
command = 'highlight -O html -f --syntax=$(echo $ATTR_CLASS | sed -e
"s/language-//")'
```

Thanks,
Jonah
Details
Message ID
<e230eb8f-d8ae-0857-e058-74383ef8001d@baturin.org>
In-Reply-To
<CACAg5t4j8bPy8ZJJa_s2dFvRgUPORXseBSVB7JTwSw9xoZJ2Yg@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
On 4/12/20 3:36 AM, Jonah G wrote:
> Just started trying out soupault today and got it working, but have
> two questions:
>
> 1. What if I have more than 1 "main template"?  Ie, some pages should
> be embedded in template1, others in template2.  I know I could just
> copy the full html for template2 for every page that requires it, but
> that would be repetitive and unmaintainable.  What I want is way to
> specify on the page: "This page should be embedded in this template".
> Is there a way to achieve that?
>
> 2. Is it possible to select the content of an attribute rather than
> the text content of the node.  Eg, say I want  the
> `index_date_selector` to populate the `date` field with the value of
> the attribute `time[datetime]`.  If I specify that as the selector, it
> still selects "content" from `<time
> datetime="2020-04-11">content</time>`.  I did find the example below,
> but it doesn't seem exactly analogous.
>
> ```
> selector = '*[class^="language-"]'
> command = 'highlight -O html -f --syntax=$(echo $ATTR_CLASS | sed -e
> "s/language-//")'
> ```
>
> Thanks,
> Jonah

Hi Jonah,

>What I want is way to specify on the page: "This page should be
embedded in this template".
>Is there a way to achieve that?

What do you think a good configuration syntax for it would be?
I anticipated that some day someone will want it, so there's room in the
code for implementing it.
However, I didn't want to create a syntax that real users of that
feature would hate.

One my idea is a "templates" section with the same options as we already
have for limiting widgets to specific pages:

[templates.foo]
  file = "templates/foo.html"
  page = ["foo.html", "bar.html"]
  section = "quux"

Does this look good to you?
If yes, it's doable for the late April release.

>Is it possible to select the content of an attribute rather than the
text content of the node.

I can't think of a case in HTML where an attribute content is data
rather than metadata, so I haven't even thought about it.
A workaround would be to make a plugin that extracts element content and
places it in a temporary element, and a delete_element widget to clean
it up after extraction is done.

A nice solution would be to add support for indexing plugins, but that
requires a serious design discussion (which everyone is welcome to join).
Details
Message ID
<ab96281d-77c2-fb53-a1be-3c8d3bd52a05@aoirthoir.com>
In-Reply-To
<e230eb8f-d8ae-0857-e058-74383ef8001d@baturin.org> (view parent)
DKIM signature
pass
Download raw message
I have made several plugins over the last week and several functions 
that all plugins can use. I have some more to do tomorrow..and then I 
will be uploading them to my website for review, and so on.

Among these is a template finding plugin that decides based on where you 
are what template to use...

So this is actual code from a site that I have up for a friend in the 
soupault.conf file (the site is in the test phase but yall can see it at 
http://dannydemar.com )

[widgets.insert-header]
   widget = "tree-template-include"
   file = "header.html"
   selectors = "header"

[widgets.insert-footer]
   widget = "tree-template-include"
   file = "footer.html"
   selectors = "footer"

The plugin tree-template-include looks at whatever file soupault is on 
in site/whatever... so /en and /es obviously need different headers... 
footers and more... and obviously /en/sales/callus.html and anything 
else under /en needs that consistent header as well... tree template 
plugin solves that...

It is useful for more than just language situations.. you can have 
different includes for any directory structure...

The way it works is this... it looks at your page...

site/en/sales/candy/caramel/box.html

will check the following in order....

templates/en/sales/candy/caramel/header.html
then
templates/en/sales/candy/header.html
then
templates/en/sales/header.html
then
templates/en/sales/header.html
then
templates/en/header.html
then
templates/header.html

When it finds a header.html it uses it. If it doesnt find the 
header.html it ends the plugin.

The logic can be applied anywhere you want down the line...

This is not exactly using different main.html themes but it is a start.
Details
Message ID
<be51b6f2-5bbf-52d6-7922-9a7343a80ae0@baturin.org>
In-Reply-To
<ab96281d-77c2-fb53-a1be-3c8d3bd52a05@aoirthoir.com> (view parent)
DKIM signature
pass
Download raw message
I've just added support for extracting attributes for custom fields. The
syntax is as follows:

```

[index.custom_fields]
  post_image = { selector = "img#post-image", extract_attribute = "src" }
  post_date = { selector = "time#post-date", extract_attribute =
"datetime" }

```

Jonah, do you have a setup for building soupault from source, or you'll
need prebuilt executables to test it?
If you need prebuilt binaries, which OS are you using?

I can't see a way to retrofit that option to build-in field syntax though.
I'm starting to think that built-in fields was a mistake and we should
eventually remove them.
It will break people's configs, but we can make a script to
automatically convert old configs to use custom fields syntax to help
people migrate.
Details
Message ID
<1164b5b5-fbd5-6e20-3914-9f6574b52bab@aoirthoir.com>
In-Reply-To
<e230eb8f-d8ae-0857-e058-74383ef8001d@baturin.org> (view parent)
DKIM signature
pass
Download raw message
I didn't fully understand what Jonah was saying. I thought he wanted to 
select elements based on their attributes which is a css selection 
possibility..

His selector = '*[class^="language-"]' is what made me think that is 
what he meant me. That will selector any element where class starts with 
language-...

The new custom fields will work if you are just looking to get one 
datetime value.. but if you want to set it throughout a list of elements 
you would use some code like i have below. in the HTML.replace_content() 
statement, if you want to update a different element, you must first 
select for that element... Lastly to be honest i dont know that this 
solves what he is looking for if he wants this for index options... but 
it is useful for other cases...

In his plugin code he could do something like this

local elements
local elementsCount
local elementsIndex
elements = HTML.select(parent, selector)
elementsCount = size(elements)
elementsIndex = 1
while (elementsIndex <= elementsCount) do
   element = elements[elementsIndex]
   datetime = HTML.get_attribute(element, "datetime")
   if datetime then
      datetime = HTML.create_text(datetime)
      HTML.replace_content(element,datetime)
   else
      do whatever else you wanna do....
   end
end
Reply to thread Export thread (mbox)