How to change Hugo's post image - hugo

I want to change hugo's post image.
+++
title = "how to read the book"
draft = false
date = "2017-01-25T21:39:26-06:00"
image = "book.jpg"
+++
Hello World. New Book Review.
I put book.jpg under mywebsite/static/images/ directory. But the post still using the default image.
Any suggestions?

I solved this issue by changing image = "book.jpg" to thumbnail = "images/book.jpg"
I followed the official guide from https://gohugo.io/overview/quickstart/ originally. It is very confusing.

If you're using front matter to configure your posts, follow these steps:
In your config.yaml file, make sure the cover parameters are set to not hide images
cover:
hidden: false # hide everywhere but not in structured data
hiddenInList: false # hide on list pages and home
hiddenInSingle: false # hide on single page
Add the image to the static folder (ex. meteor.png)
In your post's front matter, add the following lines to reference the image
---
title: "Impact Fanatics"
date: 2022-09-27T18:03:38-04:00
draft: false
relative: true
cover:
image: /meteor.png
---

Related

Hugo content not rendering

I've used the hugo-icon single page theme to build a static site and have been asked to add a new page for product descriptions. I have read many tutorials/answers on stack and watched Mike Danes videos to date but cannot get a new page to render.
When I run the following command hugo new products/product1/_index.md a url to product1 is generated but no content is rendered. This is the content of my _index.md file;
---
title: "Product1"
date: 2021-05-24T14:47:36+01:00
draft: false
---
product1 info
I expect one of 2 things; To see 'product1 info' rendered at the url. OR I place a html file of the same name somewhere in the folder structure to render text etc. I have tried multiple locations to place html and still I cannot see anything.
Can someone explain or give an example of adding a new page to the hugo-icon theme and explain if I am missing a fundamental concept.
config:
# Main config file for icon theme.
theme = ["hugo-icon"]
baseURL = "https://www.example.com/"
languageCode = "en-ie"
title = "my site"
[params]
author = "Me"
description = "My site"
# Hero section (from here on is for icon theme)
[params.hero]
img = "images/hero_bg_green.jpg"
title = "My Site"
Thanks
I was missing this fundamental design pattern. Each folder created under layouts required a template. In my case this looked like the following where each page was designed inside the single.html file
Layouts
page1
single.html
page2
single.html
The route needs defining in the content folder inside content/pages/page-one.md like so where type is mapped to the folder name by its type definition
type : "page1"
title: "Page 1"
date: 2021-05-27T11:16:39+01:00
draft: false
My url therefore is www.example.com/pages/page-one.html which is designed in layouts/page1/single.html and mapped via the type definition to www.example.com/content/pages/page-one.md
The .md file inside content/... dictates the path to the url. The type definition dictates which page to render from layouts/...

Remove SonataAdmin logo

I am trying to remove SonataAdmin logo. I don't want any picture. Every param that I put in my .yml file I get a broken picture icon on my admin view.
I have checked the conifguration and there is no wirtten documentation of how to hide logo.
sonata_admin:
templates:
user_block: '#AdminTemplates/user_block.html.twig'
title: My App
title_logo: /bundles/sonataadmin/logo_title.png //-- this part
Put your logo file here
src/AppBundle/Resources/public/images/your_logo.png
install asset :
$ php bin/console assets:install
And I think you have just to delete the first slash / in the title_logo :
# app/config/config.yml
sonata_admin:
templates:
user_block: '#AdminTemplates/user_block.html.twig'
title: My App
title_logo: bundles/app/images/your_logo.png //-- this part
The point here is to make a transparent image , so you can't see the logo, otherwise , there is no way to do it .

React (native) image storing / fetching good practices

My use case is a mobile app with react native, but I guess it's very common good practices.
I want to be able, in an app, to take an image (from the camera or the gallery), and to be able to store it so it can be fetched from the date it was added, or some metadata added by the user.
The theory seems quite simple, a way of doing it can be :
Use any library (eg this great one) to get the image,
Store image as base64 and metadata in, let's say RealmJS (some internal DB),
Query this DB to get what I want.
This should work, and should be quite simple to implement.
But I'm wondering about a few things :
According to the performance of a smartphone's camera, isn't it quite a shame to store it as base64 (and no checksum, more memory used, ...) ?
This format, base64, isn't a bad idea in general for storing image ?
Is it a good idea to store the image in RealmJS, as it will be a pain for the user to reuse the image (share it on facebook...), but on the other hand, if I wrote it to the smartphone and store a URI, it can lead to a lot of problems (missing file if the user deletes it, need to access to memory, ...)
Is this approach "clean" (ok it works, but ...) ?
If you have any experience, tips, or good practice to share, I'll be happy to talk about it :)
You can store binary data (images) in Realm. But if you are using Realm locally (not sync), I will suggest that you store the image on the file system and store the path in Realm. Your model could be something like:
const ImageSchema = {
name: 'Image',
properties: {
path: 'string',
created: 'Date',
modified: 'Date?',
tags: 'Tag[]'
}
};
const TagSchema = {
name: 'Tag',
properties: {
name: 'string',
images: { type: 'linkingObjects', objectType: 'Image', property: 'tags' }
}
};
That is, for every image the timestamp for its creation is stored. Moreover, it has an optional timestamp if the image has been modified. The property path is where to find the image. If you prefer to store the image, you can use a property of type data instead. To find image less that a week old, you can use realm.objects('Image').filtered('created >= $1', new Date(Date.now()-7*24*60*60)).
Just for fun, I have added a list of tags for each image. The linkingObject in Tag makes it possible to find all image which have a particular tag e.g., realm.objects('Tag').filtered('#links.Tag.name == "Dog"').

Adding emoji to a Hugo page variable

How to add an emoji to a Hugo page variable? E.g. inside the title in the following code snippet:
date = "2016-11-20T12:00:00"
draft = false
tags = ["Fun"]
title = "Went sporting :heart:"
Hugo has two ways of handling Emojis.
Setting enableEmoji=true in your site config will handle emoji syntax like :heart: in your markdown content.
For titles etc. you must use the emojify template func, so in your template:
{{ .Title | emojify }}

Get meta data from delegated files using QML

I'm creating a music player for Ubuntu Touch in QML and I have some things I would appreciate some help with since I'm new to QML.
I have a list of tracks from a directory, but I want to show the meta data (artist, track name, year, album and so on) instead of the filename.
Using Qt.Multimedia am able to get the meta data from the currently playing track, but I can't find how to do it per file from my FolderListModel delegated files.
How would I do that?
This is the current code:
Column {
anchors.centerIn: parent
anchors.fill: parent
ListView {
id: musicFolder
FolderListModel {
id: folderModel
folder: musicDir
showDirs: false
nameFilters: ["*.ogg","*.mp3","*.oga","*.wav"]
}
width: parent.width
height: parent.height
model: folderModel
delegate: ListItem.Subtitled {
text: fileName
subText: "Artist: "
onClicked: {
console.debug('Debug: User pressed '+musicDir+fileName)
playMusic.source = musicDir+fileName
playMusic.play()
trackInfo.text = playMusic.metaData.albumArtist+" - "+playMusic.metaData.title // show track meta data
}
}
}
}
It seems like the easiest thing to do here would be to go get a C++ library that can parse the meta data out of these files and use it to create a custom ListModel in C++ that populates this information onto itself. Unfortunately, this will have to be done in C++ as javascript does not have the IO capabilities to read and parse files.
Actually I think I might go ahead and use QtMultimedia, but keep data in a local database. On startup, it checks the music dir and adds/removes tracks. That way it will be only be slow at first startup (hopefully)

Resources