I am trying to iterate over a variable in jade with each. the variable, in this case is interpolate like so #{images}. The array contains urls for images.
I can do img(src="#{images[0]}") and it works fine
I try to use the each functions and keep coming up with errors. This is the latest attempt.
div
each image in #{images}
img(src="#{image}",height="100px",width="100px")
i have tried without interpolating image. and a bunch of other stuff. is there something i am missing with the space or syntax?
img(src="#{images[0]}",height="100px",width="100px")
the above works so i know im getting the variable, again this is with jade extensions. i tried to migrate this little project to pug but that didnt work, but thats another story.
this is last piece in a pretty cool uploader that uses POST from the browser to upload images to an aws bucket while saving the urls in a mongoDB. figuring this out will add an image gallery to view the uploads.
So after much hassle I have figured it out. This rule should apply to most scenarios when you send an array as a variable from express over into your jade/pug template.
My issue was that I was trying to interpolate my images variable within the each loop. You interpolate like this: #{variable}. That will produce the literal version of your variable, but that is not what is needed in an each loop. You just want the name of the variable, not the literal value.
Instead the code that works is ridiculously simple.
Wrong:
each image in #{images}
img(src="#{image}",height="100px",width="100px")
Right
each image in images
img(src="#{image}",height="100px",width="100px")
Now the loop is creating a new image with a src from each value in my var images=[url,url,etc]
This jade/pug syntax is a bit confusing at first, but seems to be great if you can figure it out.
Related
How can I create a Wordcloud using NodeJS without using the browser? The libraries I could find always need the browser to generate.
A question I would ask.. What is the use case where you wouldn't want to display the wordcloud?
The libraries will generally rely on canvas to generate the word cloud so obviously it wont work unless its in the browser. If you are trying to generate something that is saved in an image then you would need a way to tally up each item, maybe in an array with its corresponding 'count' and then at the end print those words to and image with varying font sizes based on their 'count' in the array.
Again, without know the use case its hard to say for sure.
Ive been trying to figure out how to code a image into a "var svgData" code for quite some time, yet i only found one similar question in the internet with no helpful solution. There is a webisite called "gtalogo" (http://gtalogo.com/), where you can basically look for emblems you want to apply to your gta crew.
But in order to upload a image on the website, you need a "var svgData='(Code)=';var layerData='(another Code)='" first, and I have no idea how you can get that code out of a svg file, png file, jpg file, or whatever.
Ive tried to convert svg to base64, but that didnt solve the problem because there is still the "var layerData".
I can give you a example of one image which is on the gtalogo webiste, and got coded into "var svgData".
image: https://en.gtalogo.com/img/16479.webp
code: (too long), but you can see it on this link, when you click on "show code": https://en.gtalogo.com/emblem-16479.html". This is a random emblem btw.
And my task is to get the "var svgData" code, which you saw on the website, out of my image. This is the image: My image
(no questions asked (im not a communist)).
And this is the svg: https://mega.nz/file/HGJlCIQS#iOlt6jdVDGJV98Ay_HpnHudtB94rncehgCnKQgq39GY
Base64 code if you need it: https://mega.nz/file/yGRFjQCK#uslnTQe5kqxqE1RJABXnGeBkmxZ19fVPQeiPjg253ks
So, if someone knows what im talking about and is able to describe me how i can get the var svgData code, or is able to code it for me, it would be very appreciated.
TrileX_
svgData is not tied to the image itself. It's a value that Rockstar services create for each of the emblems that are successfully created.
[EDIT: While svgData is actually tied to the image and can be easily reproduced, but you still need layerData which is from Rockstar editor]
To upload an image to "gtalogo" you need to use a command in console (copy(_sc_av_edit+'|||'+document.getElementById("emblemEditor-canvasContainer").innerHTML)). First part is the code generated by Rockstar and the second part is the vector image itself.
While the second part you can get without any issues, the first part you can only get from an already saved emblem (as far as I know).
In conclusion, you either have to use a pre-existing emblem or make one yourself in the Rockstar emblem editor.
Hello I am trying to isolate a image - src=\"https:\/\/steamcommunity-a.akamaihd.net\/economy\/image\/6TMcQ7eX6E0EZl2byXi7vaVKyDk_zQLX05x6eLCFM9neAckxGDf7qU2e2gu64OnAeQ7835Ff5GLNfCk4nReh8DEiv5dbPK47pbcyR_m4DQ68Ofs\/62fx62f\" from https://steamcommunity.com/market/listings/252490/Alien%20Red/render?currency=1&format=json and put it into a embed, I am using node fetch to get the overall json from the site how would I go about doing this? I currently have a inefficient way of doing it (getting every character) and it does not work at some points. Any help is appreciated.
There will probably be a better way to do this, but I've thrown this together:
/(?!src=\\?)\"(.*?)\"/g
Just match this with the return and you will have your URL.
If you are making this a static thing (ie. it will be ONLY this image, and will not be editable depending on a command or variable, then just put it as a string & make that the embed's image.
If not, then fetch the contents, then get the results_html portion of it. Then, find where it says "<img" and isolate it until the next ">". Sub string that bad boy from where is says src= to when it sees \" . (or " depending on how it interprets this), and use that sub string as the embed's image attachment.
I would like to get images from a search engine, to run some automated tests without the need to go online and pick them by hand.
I found an old example from 5 years ago (ajax.googleapis.com/ajax/services/search/images), which sadly does not work anymore. What is the current method to do so in Python3? Ideally I would like to be able to pass a string with the search name, and retrieve a set amount of images, at full size.
I don't really mind which search engine is used; I just want to be sure that it is supported for the time being. Also I would like to avoid Selenium; I am planning to run this without any UI nor using the browser, all from terminal.
Have you heard of pixabay? There is a nice python wrapper for working with it as well.
Found a pretty good solution using BeautifulSoup.
It does not work on Google, since I get 403, but when faking the header in the request, is possible to get sometimes, data. I will have to experiment with different other sites.
So far the workflow is to search in the browser so I can get the url to pass to beautifulsoup. Once I get the url in code, I replaced the query part with a variable, so I can pass it programmatically.
Then I parse the output of beautifulsoup to extract the links to the images, and retrieve them using requests.
I wish there was a public API to get also parameters like picture size and such, but I found nothing that works currently.
I have this NodeJS application, that uses Jade as template language. On one particular page, one text block is retrieved from the server, which reads the text from database.
The problem is, the returned text might contain line-breaks and links, and an operator might change this text at any time. How do I make these elements display correctly?
Most answers suggest using a new line:
p
| this is the start of the para
a(href='http://example.com') a link
| and this is the rest of the paragraph
But I cannot do this, since I cannot know when the a element appears. I've solved how to get newline correct, by this trick:
p
each l in line.description.split(/\n/)
= l
br
But I cannot seem to solve how to get links to render correctly. Does anyone know?
Edit:
I am open to any kind of format for links in the database, whatever would solve the issue. For example, say database contains the following text:
Hello!
We would like you to visit [a("http://www.google.com")Google]
Then we would like that to output text that looks like this:
Hello!
We would like you to visit Google
Looks like what you're looking for is unescaped string interpolation. The link does not work in the output because Pug automatically escapes it. Wrap the content you want to insert with !{} and it should stop breaking links. (Disclaimer: Make sure you don't leave user input unescaped - this only is a viable option if you know for sure the content of your DB does not have unwanted HTML/JS code in it.)
See this CodePen for illustration.
With this approach, you would need to use standard HTML tags (<a>) in your DB text. If you don't want that, you could have a look at Pug filters such as markdown-it (you will still need to un-escape the compilation output of that filter).