-
-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inline image and lightbox template files #84
base: main
Are you sure you want to change the base?
Inline image and lightbox template files #84
Conversation
Hi all ! Yet another new patch, in brief: the PHOTO_INLINE_GALLERY_PATTERN python regex also define an "options" Both this patch and the previous one are 100% backward-compatible. In order to increase the flexibility of inline galleries, Hope you will enjoy it! Pirogh [email protected] |
Hi all ! Is there somebody alive here ? Pierre |
re-open, hope that something new could happen ? |
@pierresaramito I am a user of this plugin and have the problem, that the SITEURL is not substituted in inline_gallery.html. I guess this is a bug, which is fixed by your PR? The other features you included look pretty amazing to me as well! Unfortunately, I don't know if this repo is still alive (would be very sad if not!). Have you opened an issue regarding the bugs you fixed? Maybe this will create some attention and document the currently existing bugs. Let`s hope it will be merged soon! Paul |
I opened an issue for this now: #87 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few small things that should change before landing this, but by and large this looks solid.
- if you can, some tests for the options parser would be awesome.
- tests for the template loader aren't a bad idea either.
- log when templates can't be loaded please
@@ -220,6 +223,162 @@ For example, add the following to the template `index.html`, inside the `entry-c | |||
{% endif %} | |||
``` | |||
|
|||
## The new optional templates files for inline galleries, images and lightboxes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## The new optional templates files for inline galleries, images and lightboxes | |
## Optional templates files for inline galleries, images and lightboxes |
|
||
The template file to render inline galleries is loaded. | ||
The name of this file is by default ``"inline_gallery.html"``` | ||
and could be changed with the `PHOTO_INLINE_GALLERY_TEMPLATE` variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and could be changed with the `PHOTO_INLINE_GALLERY_TEMPLATE` variable. | |
and can be changed with the `PHOTO_INLINE_GALLERY_TEMPLATE` variable. |
</div> | ||
``` | ||
|
||
The ``options`` variable is a python ``dict``: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ``options`` variable is a python ``dict``: | |
The ``options`` variable is a python ``dict[str,Union[str,bool]]``: |
When there is no explicit value, the value is a ``bool``, set to ``True``. | ||
When the value is explicitely ``False``, it is also converted to ``bool``, | ||
otherwise it is left as a ``string``. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful to list the context variables available to the template here, the way you've done for the image template, below.
gallery_name = m.group("gallery_name") | ||
options_strg = m.group("options") | ||
options = {} | ||
if options_strg is not None: | ||
options_list = re.compile(r"[\^,]+").split(options_strg) | ||
r_pair = re.compile(r"(?P<variable>\w+)=(?P<value>\w+)") | ||
r_flag = re.compile(r"(?P<flag>\w+)") | ||
for opt in options_list: | ||
m_pair = r_pair.match(opt) | ||
m_flag = r_flag.match(opt) | ||
if m_pair: | ||
d = m_pair.groupdict() | ||
value = d["value"] | ||
# convert string to bool when possible | ||
if value == "True": | ||
value = True | ||
elif value == "False": | ||
value = False | ||
options[d["variable"]] = value | ||
elif m_flag: | ||
d = m_flag.groupdict() | ||
options[d["flag"]] = True | ||
else: | ||
logger.error( | ||
f"unexpected inline gallery <options> = {options_strg}" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you split this parsing out into a function? It would be easier to test (and if you put a test in for it, that'd be grand, too)
except Exception: | ||
template = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case at least please log a warning or error about the issue, rather than silently bailing.
) | ||
), | ||
lightbox_attrs = " ".join(lightbox_attr_list) | ||
content._content = content._content.replace( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gotta wonder... would it make sense to define these as template strings in the package somewhere, and then just have one path through here (if a template is set, load it, otherwise load the default template, and then render them both)?
Hi Pierre. Thanks for submitting this pull request. Could you take a moment to address the feedback that @offbyone provided so we can get your contribution merged? |
Hi Pierre. Just checking in about your contribution. What do you think? |
I do not recommend merging this PR because it has some drawbacks. Use deprecated gallery includeFirst of all it tries to improve a deprecated feature, the 'gallery' pattern. If the galleries are included into a page or article in the old way, like in the example below.
The markdown parser adds a
In the next step the photos plugin replaces the gallery pattern with the inline gallery template. This will result in a gallery inside a <p>
<div class="my-gallery">
<ul>
<li><img src=""/></li>
<li><img src=""/></li>
</ul>
</div>
</p> This might result in structural issues in the browser. Also if the photos plugin can't find the gallery it will result in the gallery pattern displayed on the output.
New patternJust use the pattern introduced in version 1.1.0
This pattern is not modified by the markdown parser and the photos plugin can replace it with the correct inline gallery template. <div class="my-gallery">
<ul>
<li><img src=""/></li>
<li><img src=""/></li>
</ul>
</div> If something went wrong and the photos plugin can't find the gallery. The div tag is still present in the output but won't be visible for your readers. Additional parametersBy default PHOTO_INLINE_PARSE_HTML is set to true. See the example below.
This will use the inline_gallery template and the image profile from your settings. Also this will make the attribute Inline Gallery, Image or lightboxJust use one of the patterns.
You can provide additional attributes/values by following the instructions from the additional parameters example. |
Hi all !
In brief:
In order to increase the flexibility of inline images and lightboxes,
I've introduced two template file provided by default as:
PHOTO_INLINE_IMAGE_TEMPLATE = "inline_image.html"
PHOTO_INLINE_LIGHTBOX_TEMPLATE = "image_lightbox.html"
Indeed, these two files was suggested in the photos.py code,
but not used in practice: perhaps it was planed for future works?
This is now achieved and the README.md doc is completed accordingly.
Also, the SITEURL variable was not propagated in "inline_gallery.html"
ind thus, it was complicated to compute full path files.
Now, SITEURL is propagated in this template file
and, moreover, it honors the RELATIVE_URLS variable from pelicanconf.py:
when RELATIVE_URLS is True, then SITEURL is propagated as ".".
Pirogh [email protected]