Fixing 'Invalid Filename' Deploy Error in Hugo - hugo

I've deployed my Hugo website using Netlify, but after my latest changes I keep getting the same error that is as follows:
Failed during stage 'deploying site': Invalid filename 'tags/c#/page/1/index.html'. Deployed filenames cannot contain # or ? characters
I can't find any file in my repository that contains such a path and my index.html doesn't contain any of those invalid characters either. I have attempted to revert the changes but I still receive the same deployment error.
Where should I be looking in my repo files to diagnose this problem?

That is pointing to an auto-generated file that lists those pages that have 'C#' as a tag in the front matter. So look for pages that have something like:
tags: [ 'C#']
in it.
In order fix, you will need to change the tag to 'c-sharp' or something similar.
Or - check that preserveTaxonomyNames is not in your site.yml (or is set to false).

This error happens when we use C# tag or other that contains # in our post/markdown because Hugo will generate static files in public folder according to the tag such as tags/c#/index.xml.
We certainly can replace with other tag like C-Sharp or similar but if we still want to see C# tag in our post there is a workaround for that.
After replacing the tag with C-Sharp for example.
tags: ["C-Sharp"]
We need to override html file where this new tag will appear, then replace following code
{{ . }}
with
{{ replace . "-Sharp" "#" }}
Please notice we replace -Sharp with # so that C# will still appear on our post but the url will be [your-site]/tags/c-sharp/ and Hugo won't generate tags/c#/index.xml in public folder. Therefore, we can avoid the error.
This is summarized from here.

Related

How to use the same layout in a different directory?

I have a site using the hugo-coder theme, which has a layouts/posts folder that specifies that anything in the "posts" folder will have a blog post format.
I would like to have two different blogs in two different subdirectories, using the same layout. Is there a way to tell Hugo that the content/blog1 directory should use the same settings and layout as the content/posts directory without copying themes/hugo-coder/layouts/posts into layouts/blog1? Ideally I would avoid using symlinks, because, while convenient, I've had a decent amount of software throw weird errors when I use symlinks, so I avoid them when it's possible.
You can set the layout or type field to posts in the frontmatter of your _index.md file in content/blog1.
See this docs page for more info.
Edit: Alternatively, you could create an archetype for blog1 that automatically sets the value to posts in the frontmatter of individual posts in that section, assuming you're using hugo new blog1/postname.md to create posts for that section.
Double edit: The first suggestion didn't work. You could also create subsections within content/posts/blog1 and set the permalinks of posts in that subsection to use the last section only. That should remove the need to explicitly set the type in post frontmatter every time because each post would already have a type of posts.
In config.toml:
[permalinks]
posts = "/:sections[last]/:slug/"
You can use a partial in your templates. If you do that you WILL need the single and list file in the layouts/blog directory, but it could be an empty file referencing the partial. The layouts/posts/single.html and the layouts/blog/single.html both will then look like this:
{{ partial "singleblog.html" . }}
Compeletely DRY... and without much complexity.

Typo3 Transform DB bodytext to frontend html

I try to import an old typo3 v4 into v10 and I'm using external_importer extension for the job. On the flow I would like to download the internal files like PDF and relink in bodytext.
The idea would be to transform the saved content to real html and evaluate the hyperlinks if are containing relative PDF links and in case trigger the download and rebuild the link to the file.
How would I proceed in this case?
I tried the following
$parseObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ContentObjectRenderer::class);
$html = $parseObj->stdWrap_HTMLparser($htmlStr, []);
DebugUtility::debug($html);
but the hyperlink steel remains as <link http://someurl.com>
I had a similar problem. If the solution is the same with mine, you are halfway there. You are missing the reference. Meaning, how should TYPO3 process the text. Here is what worked for me.
TYPO3 render full t3:// links from bodytext in utility files
First, use the parseFunc and not the stdWrap_HTMLparser. Then use this reference: lib.parseFunc. At the end you should have something like that:
$parseFuncTSPath = 'lib.parseFunc';
$html = $parseObj->parseFunc($htmlStr, [], '< ' . $parseFuncTSPath);
DebugUtility::debug($html);
And since you are using TYPO3 10, i would recommend to use DI (Dependency Injection). You can basically copy paste the code from the linked SO answer i pasted.
Best regards

How to make Sphinx resolve URL links from e.g. /about-manual to /about-manual.html

I'm creating a Sphinx documentation and I struggle to identify the "proper" way to set up the structure and links.
STRUCTURE 1#
Currently, my structure looks as below:
index.rst
about-manual/index.rst
Inside my root index.rst, the toctree is as below:
===========================
Contents
===========================
.. toctree::
about-manual/index
This results in the below links:
https://example.com/docs/ --> Content of index.rst
https://example.com/docs/about-manual --> Content of about-manual/index.rst
This works as intended in terms of link resolution
However, I'm unsure if it's the "proper" way of setting up my Sphinx structure
STRUCTURE 2#
index.rst
about-manual.rst
Inside my root index.rst, the toctree is as below:
===========================
Contents
===========================
.. toctree::
about-manual
This results in the below links:
https://example.com/docs/ --> Content of index.rst
https://example.com/docs/about-manual --> ERROR
https://example.com/docs/about-manual.html --> Content of about-manual.rst
This results in a more compact/simple Sphinx structure
However, if a user enters an URL without explicit .html at the end, the link is broken
Am I missing a basic configuration setting in Sphinx in order to make the link resolution work as per my expectation with 'STRUCTURE 2#' - without having to add the explicit .html at the end?
And is it possible to avoid having the Sphinx documentation explicitly resolve to the index.html at the end of an URL path? It does this as expected on the root index, but in 'STRUCTURE 1#' all sub pages explicitly show the index.html at the end.
I've looked at html_file_suffix and html_link_suffix, but I've not been able to make these work for my purpose either.
I found a solution for this by using sphinx-build -b dirhtml instead of sphinx-build -b html (as proposed by Jesse Tan from the sphinx_rtd_theme team) - for details see this link.
It basically lets me use the approach in 'STRUCTURE 2#', but it builds the output with an index.html files structured in folders named as per the .rst files.
Importantly, the internal links are also updated to not include the index.html part.

Why my single page in Hugo returns a 404 HTTP error?

I am trying to create a site with Hugo, but I don't get how to add a single page to my website (posts are working fine).
Starting from a fresh install (v.0.27 64x for windows) and running the following command from my terminal:
> hugo new site soexample
> cd soexample
> git clone https://github.com/parsiya/Hugo-Octopress.git themes\octopress
> hugo new about.md
> echo "Please display me" >> content\about.md
> hugo serve -D -t octopress
I can see that my draft page is rendered from the output of the last command:
...
Built site for language en:
1 of 1 draft rendered
...
but when I try to access either http://localhost:1313/about/ or http://localhost:1313/about.html, the server (not the browser) returns a white page with:
404 page not found
What am I missing ?
The problem seems to come from the selected default theme that do not render single page outside of posts section. Themes can be a tricky point for beginners as hugo isn't shipped with default one and no official theme is recommended or supported (so beginners may have to choose randomly).
So the following commands worked for me:
> hugo new site soexample
> cd soexample
> git clone https://github.com/spf13/hyde.git themes\hyde
> hugo new about.md
> echo "Please display me" >> content\about.md
> hugo serve -D -t hyde
The page http://localhost:1313/about/ is correctly rendered.
In order to render standalone pages in Hugo you need to set the type to page and make sure you have a 'single' template in your layouts.
In the about.md front-matter set type = "page". In the layouts folder under _default folder make sure you have a single.html file.
That's it, the /about page now should render properly.
Possible duplicate, How to add a new hugo static page?
I already answer in that question, copy pasting here also.
I had a similar requirement, to add static page (aboutus in this case). Following steps did the trick,
Created an empty file content/aboutus/_index.md
Created aboutus.html page layouts/section/aboutus.html
Just stumbled on here, it was drafts, but in my case the solution had an interesting wrinkle:
about/_index.md (draft)
about/other.md (not a draft)
Hugo ignores other.md when not building drafts, regardless of other.mds draft state. I'll leave it to the reader to decide if this is a bug or a feature.
I think the problem could be related to draft.
By default, the newly created content has draft: true, and hugo will exclude draft files by default.
You can change it to draft: false or use --buildDrafts option.

How to alter the prefixes EPiServer is adding to src attributes in html

I have a fragment of html which is contained in a property of a templated EPiServer page, within that html there is an img tag which has a relative url in it.
When the page is viewed, I can see the src attribute of the tag has been altered to have the prefix /ProjectName/Templates/Pages/.
I understand that this is being done by HtmlRewriteToExternal so that image files that are stored alongside the aspx template (which does indeed live in Templates\Pages) are located correctly, however the image which is intended to be part of the html fragment is in my case actually stored under PageFiles/nnn/ (where nnn is actually the parent page's PageFolderID), and I need to somehow make the altered html reflect that.
I've created a class that inherits from FriendlyUrlRewriteProvider and registered my class. I can debug the application, and watch the requests go through the overridden methods, but I still can't see where the prefix is being added or get any idea how to change it. I can alter the src tag to a different relative path in my class, but the prefix is still being added.
I've read everything I can find on the EPiServer url rewriting, but can't find anything that hints as to where this prefix is being added or how to stop that or change it.
Things I've read:
http://blogs.interakting.co.uk/post/File-Extensions-and-URL-Rewriting-in-EPiServer.aspx
http://blog.fredrikhaglund.se/blog/2008/05/07/disable-episerver-urlrewriter-interference/ (this may contain the answer I'm looking for)
http://labs.kaliko.com/2010/11/prevent-episerver-urlrewrite.html
http://sourcecodebean.com/archives/episerver-friendly-urls-for-paginated-pages-and-why-the-asplinkbutton-must-die/510
http://tedgustaf.com/en/blog/2008/7/create-a-custom-url-rewrite-provider-for-episerver/
http://tedgustaf.com/en/blog/2011/4/publishing-plain-html-pages-in-episerver/
http://sdk.episerver.com/library/cms5/Developers%20Guide/Friendly%20URL.htm
http://sdk.episerver.com/library/cms6.1/html/T_EPiServer_Web_UrlRewriteModule.htm
http://labs.episerver.com/en/Blogs/Ruwen/Dates/111218/112064/112154/
http://world.episerver.com/Blogs/Magnus-Strale/Dates/2011/3/Do-we-really-need-yet-another-HTML-parser/
http://world.episerver.com/Blogs/Yugeen-Klimenko/Dates/2011/6/How-EPiServer-URL-Rewriting-works/
http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=46869
I'm open to completely different solutions for what I'm actually trying to achieve, which is as follows:
I have multiple independent sets of static html files and related image / css / js files, which I'm trying to store / publish with EPiServer. The structure of each set looks something like
setfolder/
htmlfileA.html
htmlfileB.html
css/
styles.css
images/
piccy1.png
piccy2.png
js/
magic.js
I've figured that I should create an EPiServer page for the set, and then child pages for each html file, storing the html from the files in a property of the child pages. Currently I'm storing the related static files in the PageFiles of the relevant setfolder page, as that seems to be the most logically consistent place to put them.
It's hard to give the best solution without seeing it all infront of you. But one easy way is to alter the HTML-code when you print the property to the page.
Like <%= ChangeRelativeLinks(CurrentPage["HtmlCode"] as string) %>
And in the ChangeRelativeLinks(string htmlCode) you do a regexp or similar that changes relative links and images to the pagedir as an absolute path.
If you are storing the images in PageFiles which is a Virtual Path Provider you should be able to get the url to your file simply by using the API. On the PageData class (ie CurrentPage in your template) you have a method called GetPageDirectory() which gets the page folder.
You can read more about VPP concepts here:
http://sdk.episerver.com/library/cms6.1/Developers%20Guide/Core%20Features/File%20System/File%20System%20and%20VPPs.htm
No need for a url rewrite provider for this I think.

Resources