Replace attribute "data-original" to src in telegram instant view - xpath

I need to replace "data-original" attribute with "src" using telegram template code.
I'm running an error with a telegram instant view template.
Image source not found: src attribute expected in <img data-plugin-lazyload="" data-plugin-options="{'effect' : 'fadeIn'}" data-original="https://site.com.br/thumbs/chamadas/xbox.jpg" alt="PS5 e Xbox Series X podem atrasar por causa do Coronavírus, estima analista" title="PS5 e Xbox Series X podem atrasar por causa do Coronavírus, estima analista"/>
Original site use an attribute "data-original" in all imagens in place of "src" attribute because of lazy loading script.
I'm trying to extract data-original from tag and replace by src attribute with data-original value.
I guess I can get img nodes using:
//section[has-class("section")]//img
And I can get data-original nodes if I use:
//section[has-class("section")]//img/#data-original
Debug result:
-------
Debug 6 nodes:
[0]: data-original="https://site.com.br/thumbs/chamadas/xbox.jpg"
[1]: data-original="https://site.com.br/uploads/2020/03/15/63185/consoles-next-gen-aberta.jpg"
[2]: data-original="https://site.com.br/thumbs/chamadas/B550chamada.jpg"
[3]: data-original="https://site.com.br/thumbs/chamadas/nvidia-rtx-ampere-chamada.jpg"
[4]: data-original="https://site.com.br/thumbs/chamadas/amd-zen-3-zen-4-roadmap-0.jpg"
[5]: data-original="https://site.com.br/thumbs/chamadas/xbox-srs-x-chamada1.jpg"
I tried a lot of combinations without success like:
#replace("data-original", "src"): $body//img/#data-original
And the closest try is:
#replace("data-original", "src"): //section[has-class("section")][.//img]
But in this last code it remove all img tags and all text is putted in one line <p> only so all article have only one paragraph line with all content and no images.
Theorically "simply" (not simple) replacing "data-original" attribute to "src" would do template works.
References may help:
#1 Instant View Reference
#2 Instant View Reference
#3 Instant View Docs
#4 Medium Instant View Template

Consider using below code to resolve the problem:
#set_attr(src, #data-original): //div[has-class("section")]//img
If you have srcset attribute in your img you can use below code also, Telegram will use high resolution image automatically:
# Use Instant View version 2.1
~version: "2.1"
# Disable Lazyload
#set_attrs(src, #data-original, srcset, #data-srcset): //div[has-class("entry-content")]//img

I've made it using following snnipet:
# first of all, site use an attribute object to renderize lazy loaded images. Let convert them to img src attrbute so we cna ride of src not set error
<abc>: //div[has-class("news__text")]//img # Find all images in content div class and convert it to <abc>
#set_attr(src, ./#data-original) # Set src attribute from data-original
$imagetag # var to current <abc>
<img>: //div[has-class("news__text")]//abc # Find abc and convert it to <img> again with seted src
All based on response of #haacki47 in:
https://stackoverflow.com/questions/54786100/extract-create-and-append-using-xpath-and-telegram-instant-view

Related

thymeleaf html tag with img file extension wild card

I have a thymeleaf html tag that displays an image but the image could be a jpg or it could be a png.
Example
<img th:src="'http://localhost:8081/'+#{'/images/'}+${image}+'.jpg'"/>
I need to substitute the '.jpg' for a wild card extension so as to display either jpg or png
does anyone know what that piece of code at the end is?
Thanks
I don't think it is possible. Thymeleaf has no way to detect what is the type of the file and the browser need the full path of the file to show it.
I would advice to detect/add the file extension at the same place your set the ${image} value.
For example by converting the "image" variable to an object with "name" and "extension" fields
<img th:src="'http://localhost:8081/'+#{'/images/'}+${image.name}+${image.extension}"/>

Render an image conditionally in Vue with file loader

I'm using Webpack to compile my Vue production bundle and it loads my images properly because they are defined used <img> tags in my component. I want to load an additional image and show it based on a condition. Since the image isn't set initially in an <img> tag Webpack isn't loading it using file-loader. When I call:
event.currentTarget.children[2].innerHTML = "<img src='../assets/imgs/heart.png' />"
This doesn't work because heart.png was never processed by file-loader, while my previous images were. Any ideas on how to force Webpack to process this image without defining it in HTML my component. My other images (that work) look like this : <img src="data:image/png;base64,iVBORw0KGgo...=="> I understand why my image isn't loading (it's defined in a string), buy any suggestions?

How to add an image to asciidoc book cover page?

I would like to create a pdf book using asciidoc. The title page should include the title, subtitle and an image. So far I could not find any documentation on how to achive this.
Intuivly I would do something like
My book title
=============
:author: myself
:toc:
image:images/titelimage.png[width=400]
but this just adds image:images/titelimage.png[width=400] as a subtitle. What I would like to have is something like
My book title
<titleimage>
subtitle
Is there a way to do this in ascciidoc? If not, what do I need to do to get this?
If you're using asciidoctor-pdf you can define an attribute for the logo. It will place the image above the document title.
:title-logo-image: images/titelimage.png
See an example pdf here and the raw adoc.
If anyone is still looking for this answer, this is the correct way to do it (using asciidoctor-pdf):
= Book title
Authors
:front-cover-image: image::./images/title_page.png[]
This gives you the image by itself as the first page followed by a page that shows the title, authors, revision etc.
If you want the image on the same page as the title and author, you need to use :title-logo-image: instead.
If you want a PDF using the docbook 4.x output you should:
Generate a docinfo file with an image for the front page. This is an XML file looking like the following example. It is discussed at http://www.methods.co.nz/asciidoc/userguide.html#X87
Example:
<mediaobject>
<imageobject>
<imagedata align="center" depth="400" fileref="../images/tiger.png" />
</imageobject>
</mediaobject>
<subtitle>Subtitle of this book</subtitle>
Then, customize your DocBook stylesheets to include the media element for the title page (by default the stylesheets do not include this). http://www.sagehill.net/docbookxsl/TitlePagePrint.html
DocBook 5 includes a cover element in its stylesheets.
This:
= The Book's Title
:author: First Last
:email: first.last#company.com
:toc:
:toc-placement: preamble
:doctype: book
image:./images/title_page.jpg[]
Produces:
My book title
first.last#company.com - first.last#company.com
Image
Table of Contents
...
you just need to add a empty line between the toc and the images: instruction. That's how asciidoc kinda separates blocs.

Fancybox shows blob as string not image (Ruby issue?)

I am displaying an image obtained from a database (stored as a long blob) in an img tag using the following method:
<img src="http://localhost:3000/show_image/265" />
The show_image function takes the image data from the database and renders it to the img tag using the send_data method.
When applying Fancybox onto the img tag, the data is displayed as BLOB data not the image..
Can anyone suggest a reason why? Or how I can solve this?
1) You have to apply fancyBox to the links (not the images) and the structure should be like this -
<a class="fancybox" href="big_image"><img src="small_image" /></a>
Example - http://jsfiddle.net/CYCeM/.
Well, it is actually possible to have only images, but then you have to use "data-fancybox-href" attribute to specify the large one - http://jsfiddle.net/6ZSWB/
2) Looks like the script would not be able to guess the content type from your hrefs. You have to either -
a) Create links having extension, e.g., "http://localhost:3000/show_image/265.jpg"
b) Set content type for fancybox, example - $('.fancybox').fancybox(type : 'image');
setting :type => "image/jpg" fixed the issue. I looked up the MIME content types and realised it was incorrectly written.

How do I add an image to an item in RSS 2.0?

Is there a way to send only an Image with a link and some alt text for each item in an RSS feed?
I looked at the enclosure tag but this is only for videos and music.
The enclosure element can be used to transmit pictures. The RSS 2.0 spec is quite clear about that, saying that the type is a MIME type. It does not say it is restricted to audio or video.
Here's an example: a set of photo feeds from Agence France Presse
One of solutions is to use CDATA in description
<![CDATA[
Image inside RSS
<img src="http://example.com/img/smiley.gif" alt="Smiley face">
]>
Note, that you may have a problem with hotlink prevented site.
This is possible in RRS2,
see
http://cyber.law.harvard.edu/rss/rss.html#ltenclosuregtSubelementOfLtitemgt
So you have to use the enclosure tag, to add media
You should use the enclosure tag within item to include the image. You can use it for images by setting the correct Mime Type (for example: image/jpeg) and including the image size as the "length" attribute. The length attribute doesn't need to be completely accurate but it's required for the RSS to be considered valid.
Here's a helpful article that discusses this and other options.
To work with the Mailchimp RSS to email feature, they expect the image to be specified in a <media:content> element inside <item>. This is their source for the feed item's image macro in their templates.
Thus, you need to add to the declarations
xmlns:media="http://search.yahoo.com/mrss/
Then inside the <item> element add
<media:content medium="image" url="http://whatever/foo.jpg" width="300" height="201" />
Without the extra declaration, the feed is invalid since media:content is not a known element.
Inside tag ITEM
<image:image xmlns:image="http://web.resource.org/rss/1.0/modules/image/">
http://domain. com/image.jpg
< /image:image>
Inside Description Tag
<![CDATA[
Some Text..
<br/><img src='http://domain. com/image.jpg' ><br/>
More Text
]]>
Regarding the <p> tag issue, You need to encode html within the xml.
Your code would look something like this:
<description><p> Text in the tag </p></description>
Since you are using php you can use htmlentities() to encode the html tags. They look horrible in the xml but RSS readers know what to do with it.
http://php.net/manual/en/function.htmlentities.php

Resources