Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/chipzoller/hugo-clarity.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authorIvan Boothe <git@rootwork.org>2022-04-08 03:39:41 +0300
committerIvan Boothe <git@rootwork.org>2022-04-08 03:39:41 +0300
commit2e7afb82c973614609ccefeb855d12594b066538 (patch)
tree85848181db90bc5f8800c4febd713e8e6e4ab658 /assets
parent487c8615ce28fc30255e1e509a2b2f311fe16e63 (diff)
provide a way to have alt text without a caption
Signed-off-by: Ivan Boothe <git@rootwork.org>
Diffstat (limited to 'assets')
-rw-r--r--assets/js/index.js46
1 files changed, 32 insertions, 14 deletions
diff --git a/assets/js/index.js b/assets/js/index.js
index 6a1c0c1..007daf2 100644
--- a/assets/js/index.js
+++ b/assets/js/index.js
@@ -258,30 +258,48 @@ function fileClosure(){
modifyClass(figure, 'inline');
}
- // Figure numbering
- let captionText = image.title.trim().length ? image.title.trim() : alt;
+ // Image captions
+ let addCaption = true
+ let captionText = ''
- if (captionText.length && !containsClass(image, 'alt' && !isInline)) {
- imagePosition += 1;
- image.dataset.pos = imagePosition;
- const showImagePosition = showingImagePosition();
+ if(image.title.trim().length) {
+ captionText = image.title.trim()
+ } else {
+ if(image.title === " ") {
+ addCaption = false
+ } else {
+ captionText = alt
+ }
+ }
+ // Don't add a caption for featured images, inline images, or empty text
+ if(
+ image.matches(`.${featuredImageClass}`) ||
+ containsClass(image, 'alt' && !isInline) ||
+ !captionText.length
+ ) {
+ addCaption = false
+ }
+
+ if (addCaption) {
let desc = document.createElement('figcaption');
desc.classList.add(imageAltClass);
+ // Add figure numbering
+ imagePosition += 1;
+ image.dataset.pos = imagePosition;
+ const showImagePosition = showingImagePosition();
const thisImgPos = image.dataset.pos;
- // modify image caption is necessary
captionText = showImagePosition ? `${showImagePositionLabel} ${thisImgPos}: ${captionText}` : captionText;
desc.textContent = captionText;
- if(!image.matches(`.${featuredImageClass}`)) {
- // add a caption below image only if the image isn't a featured image
- if(image.nextElementSibling) {
- // check if a caption exist already and remove it
- image.nextElementSibling.remove();
- }
- image.insertAdjacentHTML('afterend', desc.outerHTML);
+ // If a caption exists, remove it
+ if(image.nextElementSibling) {
+ image.nextElementSibling.remove();
}
+
+ // Insert caption
+ image.insertAdjacentHTML('afterend', desc.outerHTML);
}
});