Add raw html page as post

#1

I am using Academic theme. I wish to put some raw html page as post. but sounds like it doesn’t show correctly on my post pages. my html page has title there!

<html>
<head>
  <meta charset="utf-8">
  <title>Example html post</title>
</head>
....

How show I change my theme to show my raw html posts?

#2

put it under /static/post, it will only copied.
/static/<path> will get /<path>

1 Like
#3

another option is to create a _default/ layout file called blank.html that only shows {{ .Content | safeHTML }} then set the frontmatter layout to this:

---
layout: blank
---

This way you don’t need to separate your content.

1 Like
#4

You can also put raw HTML in /content without front matter.

2 Likes
#5

Please put it as hint under https://gohugo.io/content-management/formats/ or so

#6

I try the solutions but sounds like not work as expected. so I switch to a more simple theme XMin by Yihui.

That theme is easy to understand so I change below file:
themes/hugo-xmin/layouts/_default/list.html
{{ partial “header.html” . }}

{{if not .IsHome }}
<h1>{{ .Title | markdownify }}</h1>
{{ end }}

{{ .Content }}

<ul>
  {{ range (where .Data.Pages "Section" "!=" "") }}
  <li>
    <span class="date">{{ .Date.Format "2006/01/02" }}</span>
    {{if .Title }}
        <a href="{{ .URL }}">{{ .Title | markdownify}}</a>
    {{ else if in .File.BaseFileName "index" }}
        <a href="{{ .URL }}">{{ replaceRE ".*?([^/]+)/$" "$1" .File.Dir }}</a>
    {{ else }}
        <a href="{{ .URL }}">{{ .File.BaseFileName | humanize | title}}</a>
    {{ end }}
  </li>
  {{ end }}
</ul>

{{ partial "footer.html" . }}

Now I can see my html page on list but the date for html post is 0001/01/01 always:
2017/06/14 Another Note on A blogdown Tutorial
* 2017/06/13 A Quick Note on Two Beautiful Websites
* 2016/02/14 A Plain Markdown Post
* 2015/07/23 Lorem Ipsum
* 0001/01/01 2018 11 22 Hello
* 0001/01/01 filetransfer

Even if I change the html name to 2018-11-22-hello.html, it doesn’t work!

How can I modify the theme to get correct html page date?

The draft version has been pushed to Hugo-xmin.git

The example html page is content/post/2018-11-22-hello.html

#7

We can assist, but we need to see your project to understand why that is happening. For instance, that could be caused by your config, the theme template, or the front matter in the content. Check out Requesting Help and share a repo and I’m sure someone will figure it out. :slight_smile:

#8

Thanks! I have updated my post and put the github link there

#9

You need to attach the page date to the page. This is normally done in front matter, but https://github.com/wjj1928/Hugo-xmin/blob/master/content/post/2018-11-22-hello.html doesn’t contain front matter.

I believe you can put front matter at the top of HTML files, search the forums and read up on it, that is a possible fix. :slight_smile:

#10

Great, I can fix it by add below lines at the beginning of html file:

title: hello html
date: ‘2018-11-22’
categories:
- Example
tags:
- Markdown

But as a user, I wish only copy a html page to folder then everything is done! if no such header there, then use file creation date as date! how can we add code to implement it in theme?

#11

Change your config file to get the file modification time.