I have a simple problem on Hugo. I'm trying to change the length of the summaries of posts on a list page displaying them.
If I resume the structure of my layouts and content folders, it's like this:
layouts
|--- _default
|--- baseof.html
|--- list.html
|--- single.html
|--- blog
|--- list.html
|--- single.html
content
|--- blog
|--- posts
What I did is adding the following line code in my config.toml:
summaryLength = 10
But it didn't worked. How can I do it then ?
Try putting the summaryLength=10 after the theme=whatever and before params. The order of variables matter in the config.toml files.
Related
A page on my site calls .Resources.Match to fetch a group of content files that I expect to have their own .Resources property, but do not. I would like to fetch the page, then get a resource. The content structure is like a page bundle, and I've added [[resources]] to the front matter, but neither .BundleType nor Resources is set (.Resources returns an empty array). How can I get the content, then the resource?
Directory
page/
├─ index.md
└- leaf_bundles/
└- leaf/
├─ index.md
└─ resource.etc
Template page/index.md
{{ $leaf := .Resources.Match "leaf_bindles/**/*.md" | index 0 }}
{{ $leaf.IsPage }} // => true
{{ $leaf.Resources }} // => []
Content Front Matter leaf/index.md
[[resources]]
name = "resource"
src = "resource.etc"
I assume that if I were to create a template for "leaf", .Resources would be populated in that context. Is it possible to fetch leaf bundle resources from a page returned itself by a call to .Match?
I was able to achieve the desired result -- accessing page bundle content and resources from a parent page -- using .Pages and the where operator. Instead of calling .Resources.Match to fetch the .md file of a page bundle, .Pages where "Type" "mySection" returns the page bundle in its entirety, including a pointer to its resources. I set the "type" in front matter, and am good to go.
Thanks to misterbisson whose post led to my solution.
Is there anyway to create a hugo page which has no direct links? I would like to be able to create a markdown file for a page but only allow people to find the page if they have a direct link.
Yes it is possible. It really depends on how you are generating your pages. As for now I am showing two ways you can do it.
Way 1: Your _default/list.html generates the list of links to your content. You can customize that to exclude a link. Watch the if conditional.
{{ range .RegularPages }}
{{ if (not in .Title "title of page to exclude") }}
<li>
{{.Date.Format "2006-01-02"}} | {{.Title}}
</li>
{{ end }}
{{ end }}
Way 2: Alternatively you can put an html file in the static folder of your hugo directory. If the directory does not exist, you can create it. No direct links will be generated for static contents unless you explicitly link to it from somewhere else.
You can put all pages you do not want to list into a separate content sub-folder and not include it in the menu.
For example, my setup:
content
├── blog
├── notes
└── voice
Where only voice and blog have menu items, so everything in notes can not be accessed by links from the site.
I'm trying to set one of my sub-pages as a landing page in my hugo.io page setup. But all I can find so far is the hint to change the content of the home.html file in my layout folder.
This is not what I want to do, because by this I will duplicate the existing layout file for the sub-page whis is error prone. Is there any Site parameter that sets my sub-page "Portfolio" to be my landing page?
My setup:
|content
|posts
|about
|portfolio
|work1 (This is a page bundle)
|work2 (This is a page bundle)
index.md (Page Content File)
_index.md (List File)
My template setup:
|layouts
|_default
list.html
single.html
|portfolio
list.html
single.html
index.html
home.html
So layouts/portfolio/list.html ranges through all my portfolio work. This works fine. The file is used when I navigate to localhost:1313/portfolios.
But for having the same content on localhost:1313/ I understand to duplicate the layoutfile to layouts/home.hmtl -> Is this correct? This seems utterly laborious to me. Is there a more convenient way to tell hugo "use the file content/portfolios/_index.md as my landing page"?
Hope you can help me, Thanks in advance!
One solution is to move the content of layouts/portfolio/list.html to a partial, then include this partial in both layouts/portfolio/list.html and layouts/index.html. This way you will not have to duplicate the code you use to list all of your work.
I would also advice you to read the documentation on order lookup for templates, specifically the section related to the home page, as this explains the order of which template files are included.
I've got a requirement to build a section page that is comprised of some static header material, static footer material, and several sections of user-managed content. This user managed content is fragmentary, and as such should not have a permalink.
I thought that a good way to do this might be to use headless pages.
It looks like to do that, these fragments must have a directory with an index.md, and should be accessible using the .Site.GetPage operator.
I'm struggling with figuring out how to use .Site.GetPage to get a list of pages to iterate over. There will be 2..n user sections, and I don't want to rebuild the section's template if the number of content modules changes.
I'm assuming either there's some magic to query multiple pages using .Site.GetPage, or there's an entirely different operator for this.
That, or I've completely misunderstood how to use headless pages.
Here's my template for the section (../layouts/the-range/section.html):
{{ define "main" }}
<div id="page-wrapper">
<div class="halfhero" id="map"></div>
</div>
{{ $sections := .Site.GetPage "/the-range/*" }}
<!-- leaf content at .../content/the-range/*/*.md -->
{{ range $sections }}
<section class="range-section">
<div class="section-content">
{{.Content}}
</div>
<img src="{{.Site.BaseURL}}{{.Params.images}}">
</section>
{{ end }}
{{ end }}
The headless content is just a series of markdown files as leaf bundles.
Via the Hugo community at https://discourse.gohugo.io/t/using-headless-pages-in-section-lists-in-hugo/15275/2
Given a structure like this:
content/headless/
├── index.md # headless = true in front matter
├── five.md
├── four
│ └── index.md
├── one
│ └── index.md
├── three
│ └── index.md
└── two
└── index.md
You can do:
{{ $headlessbundle := .Site.GetPage "/headless" }}
{{ range ( $headlessbundle.Resources.ByType "page" ) }} <br>
{{.}}
{{ end }}
Which should output:
Page(/headless/five.md)
Page(/headless/four/index.md)
Page(/headless/three/index.md)
Page(/headless/two/index.md)
Page(/headless/one/index.md)
Hi I include one file in to another one in angular js.
I have folder structure like below
|__ image
|__ image.jpg
|__ top.html
|__ detail
|__ detail.html
Ex:
top.html
<img src="image/image.jpg" />
this one shows the image correctly.
I included this top.html file in detail.html
so the image not showing because of including the file one in another which is inside the folder.
If I want to call the image in detail.html then I can call like below
<img src="../image/image.jpg" />
But I included the file top.html which have the image, so the problem.
can anyone help to so the problem.
Use an absolute path : /image/image.jpg will refer to the same location wherever you are located.
An absolute path will begin with a slash that refers to the server root.