hugo URLs with protocol (http) not supported - hugo

I am using hugo (https://gohugo.io/) and trying to make an external link in the menu (docsy theme).
I changed the _index.md to:
---
title: "Documentation"
linkTitle: "Documentation"
url: "https://www.myurl.com"
weight: 20
menu:
main:
weight: 20
---
However hugo reports:
Rebuild failed: URLs with protocol (http*) not supported
Could anyone advise of how to create an external URL link directly on the menu?
Thanks, Gregor

Keep in mind that "url" is a predefined front matter variable that is meant to be used for defining the full path to the content page from the site root. If you want to add an external link in your front matter, I'd recommend giving the variable a different name, e.g. "external_url".

I just added something like this:
[[menu.main]]
name = "GitHub"
weight = 50
url = "https://github.com/google/docsy/"
To the config.toml file.
I found this solution for the docsy theme here: https://www.docsy.dev/docs/adding-content/navigation/
Hope this helps, Gregor

Related

How do I get Cloudcannon image inputs to work with Hugo image processing?

I'm trying to use Cloudcannon as a CMS for a Hugo-based website. For some of my content types, I use Hugo's image processing, which means I store those images that need to be processed under assets/ rather than static/.
Cloudcannon allows for image inputs to be configured with a custom upload directory, which I need to go to the correct subdirectory of assets/images/ for each content type. That works fine--the images are uploaded to the right location. The problem is that then the frontmatter path for the image includes the assets/ part of the directory path, which doesn't work for Hugo.
My configuration is as follows, allowing images uploaded for different content types to go in different subdirectories of assets/images/.
collections_config:
news:
schemas:
default:
path: schemas/news.md
name: News post
path: content/english/news
_inputs:
image:
type: image
options:
uploads_dir: assets/images/news
clients:
schemas:
default:
path: schemas/client.md
name: Client listing
path: content/english/clients
_inputs:
image:
type: image
options:
uploads_dir: assets/images/clients
Is there any way to set the fontmatter output path to exclude assets/? Maybe there's a separate option from uploads_dir I haven't found?
Help greatly appreciated!
You can set a static path here. The static path is used when uploading new files, but is not saved as part of the path for the front matter field. It's set globally, and defaults to your Hugo --staticDir command line option (defaults to static).
Here's how you would set it up for your code example:
Create or add to /cloudcannon.config.yml:
paths:
uploads: assets/images/[collection]
static: assets
Uploading a new file called cat.png on an input in the news collection here is sent to: /assets/images/news/cat.png. The value saved in the front matter is /images/news/cat.png.
I've also set a global uploads path here with the [collection] placeholder, which will have the same result as your uploads_dir options - and you won't have to set it multiple times.

Is there a way to rename automatically generated routes JSON file in Next.js?

I have a problem, when I click to go to the /analytics page on my site, adblockers block the analytics.json file that's being requested by Next.js as they think it's an analytics tracker (it's not, it's a page listing analytics products).
Is there a way to rename the route files Next.js uses when navigating to server-side rendered pages on the client-side?
I want to either obfuscate the names so they're not machine readable, or have a way to rename them all.
Any help appreciated.
With thanks to #gaston-flores I've managed to get something working.
In my instance /analytics is a dynamic page for a category, so I moved my pages/[category]/index.tsx file to pages/[category]/category.tsx and added the following rewrite:
// next.config.js
module.exports = {
async rewrites() {
return [
{
source: "/:category",
destination: "/:category/category",
},
];
},
};
This now gets the category.json file rather than analytics.json, which passes the adblockers checks and renders as expected.
Note that due to having a dynamic file name in the pages/[category] directory (pages/[category]/[product].tsx), I had to move that to pages/[category]/product/[product].tsx as I was seeing the /analytics page redirected to /analytics/category for some reason without this tweak.

How to change the url of gatsby sitemap?

I used https://www.gatsbyjs.com/plugins/gatsby-plugin-sitemap/ to create the sitemap for my website.
Currently, the sitemap is listed at https://www.myWebsite.com/sitemap/sitemap-0.xml, but I want it to be located at https://www.myWebsite.com/sitemap.xml
How can I change the sitemap's location? Sorry if this is obvious
You can't automatically since there's no option nor configuration to do so. Your only change is using any small Node script that changes the filename or doing it manually.
However, there's no SEO problem at all having a sitemap-0.xml as long as you point your Google's Search Console to that file.
Another solution is using gatsby-plugin-advanced-sitemap which by default outputs a file named sitemal.xml as you can see in their example: https://gatsby.ghost.org/sitemap.xml. This plugin is based on the one you are using so it should be quite straightforward swapping between them.
Another solution is to use the same gatsby-plugin-sitemap plugin and then add:
gatsby-plugin-robots-txt plugin and point to the file name in the gatsby-config Something as bellow:
{
resolve: 'gatsby-plugin-robots-txt',
options: {
host: SiteConfig.url,
sitemap: ${SiteConfig.url}/sitemap.xml, HERE PLACE sitemap-0.xml
policy: [{ userAgent: '*', allow: '/' }]
}
},
After doing that, look for set up on webpage/robots.txt to see where is the point

Use variable language specific strings in hugo config file

My goal is to build a multilingual site using hugo. For this I would like to:
not touch the theme file
have a config file which defines the overall structure for all languages (config.toml)
have a "string" file for all languages
So for example, I would have a config.toml file like this:
[params.navigation]
brand = "out-website"
[params.navigation.links]
about = $ABOUT_NAME
services = $SERVICES_NAME
team = $TEAM_NAME
impressum = $IMPRESSUM_NAME
a english language file:
ABOUT_NAME=About
SERVICES_NAME=Services
TEAM_NAME=Team
IMPRESSUM_NAME=Impressum
and a german language file like this:
ABOUT_NAME=Über uns
SERVICES_NAME=Dienste
TEAM_NAME=Mitarbeiter
IMPRESSUM_NAME=Impressum
And then I want to compile the project for english, I do something along the line of:
hugo --theme=... --config=config.toml --config=english.toml
and german:
hugo --theme=... --config=config.toml --config=german.toml
Or in same similar way.
For this I need to use variables in the config.toml that are defined in english.toml or german.toml
My google search so far say, that I cannot use variables in toml.
So is there a different approach with which I could achieve this?
Your approach with variables is not optimal, use the tutorial below.
Multilingual sites are coming as a feature on Hugo 0.16, but I managed to build a multilingual site on current Hugo using this tutorial and some hacks.
The tutorial above requires to "have a separate domain name for each language". I managed to bypass that and to have to sites, one at root (EN), and one in the folder (/LT/).
Here are the steps I used.
Set up reliable build runner, you can use Grunt/Gulp, but I used npm scripts. I hacked npm-build-boilerplate and outsourced rendering from Hugo. Hugo is used only to generate files. This is important, because 1) we will be generating two sites; 2) hacks will require operations on folders, what is easy on npm (I'm not proficient on building custom Grunt/Gulp scripts).
Set up config_en.toml and config_de.toml in root folder as per tutorial.
Here's excerpt from my config_en.toml:
contentdir = "content/en"
publishdir = "public"
Here's excerpt from my config_lt.toml (change it to DE in your case):
contentdir = "content/lt"
publishdir = "public/lt"
Basically, I want my website.com to show EN version, and website.com/lt/ to show LT version. This deviates from tutorial and will require hacks.
Set up translations in /data folder as per tutorial.
Bonus: set up snippet on Dash:
{{ ( index $.Site.Data.translations $.Site.Params.locale ).#cursor }}
Whenever I type "trn", I get the above, what's left is to paste the key from translations file and I get the value in correct language.
Hack part. The blog posts will work fine on /lt/, but not static pages (landing pages). I use this instruction.
Basically, every static page, for example content/lt/duk.md will have slug set:
slug: "lt/duk"
But this slug will result in double URL path, for example lt/lt/duk.
I restore this using my npm scripts task using rsync and manual command to delete redundant folder:
"restorefolders": "rsync -a public/lt/lt/ public/lt/ && rm -rf public/lt/lt/",

SSAS. How to open FILE:// via Actions in Excel

I have created an attribute called LinkToImage inside Item dimension. Attribute store paths to files in following:
file://\\localhost\dir\img1.jpg
file://\\localhost\dir\img2.jpg
and so on...
I've created an action via Visual Studio 2013 in following:
MyCube.cube > Actions >
Name: Link To Image
Target type: Attribute members
Target object: Item.Link To Image
Action content Type: URL
Action expression: [Item].[Link To Image].CURRENTMEMBER.NAME
Additional properties Caption: "Link To Image"
In this case I got warning:
The urls that do not begin with "http://" or "https://" are
considerend unsafe and will not be displayed by most applications
After deploying and exporting It to Excel In Additional Actions I see No Actions Defined
If I change Action Expression to: "HTTP://" + [Item].[Link To Image].CURRENTMEMBER.NAME
In Excel appears Additional Actions > Link To Image, but not working because It adding HTTP:// protocol in front of path and It's not accesable in that way:
http://file://\\localhost\dir\img1.jpg
Have you ideas how to achieve that without adding http://?
I don't believe there is any way other than building a website to display those images and having your action link to the website. Excel only shows HTTP(S) actions not other types of URLs.
Refer to this whitepaper for the proof that Excel specifically only renders HTTP(S) type URL actions:
http://www.microsoft.com/en-us/download/details.aspx?id=9982

Resources