Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add content template #48

Merged
merged 1 commit into from
Aug 24, 2021
Merged

Add content template #48

merged 1 commit into from
Aug 24, 2021

Conversation

helfper
Copy link

@helfper helfper commented Aug 24, 2021

I think making content a template would be useful for people who want to do some automatic processing across the whole site. An example of that can be to enable people to add support for wiki-style links (as described here: matcornic/hugo-theme-learn#469) on their own, even if Hugo or the theme don't support it natively.

People can just add something like this to their own site under layouts/partials/content.html:

{{- $wikilinks := .Content | findRE `\[\[[^\]]+\]\]` }}
{{- $content := .Content }}
{{- range $wikilinks }} 
    {{- $text := . }}
    {{- $title := $text | strings.TrimPrefix "[[" | strings.TrimSuffix "]]" }}
    {{- range where site.Pages "Params.title" $title | first 1 }}
        {{- $content = replace $content $text (printf `<a href="%s">%s</a>` .RelPermalink $title) }}
    {{- end }}
{{- end }}
{{- $content | safeHTML }}

Another use case I have is that I'd like to automatically "linkify" JIRA tickets with a given pattern XYZ-1234.

@McShelby
Copy link
Owner

The patch seems reasonable and I don't expect any migration issues.

Nevertheless I must admit, although I am a programmer in real life, I am a go and Hugo noob. Some syntax still puzzles me and I have only hit the tip of Hugo's feature iceberg.

@McShelby McShelby merged commit a47e7a6 into McShelby:2.0.0 Aug 24, 2021
@McShelby McShelby linked an issue Aug 24, 2021 that may be closed by this pull request
@helfper helfper deleted the content-template branch August 24, 2021 23:16
@jehoshua7
Copy link

Will the template for content also make it easier for applying content changes on a mass/site level ? I'm in the middle of making changes to suit the site content, and wonder if I have to redo some changes in the event of a complete re-installation of the theme ? At present the content changes are simply copied from a backup.

@McShelby
Copy link
Owner

Will the template for content also make it easier for applying content changes on a mass/site level ?

That depends on the kind of changes you want to apply. But in my general fealing I'ld say "Yes".

wonder if I have to redo some changes in the event of a complete re-installation of the theme ?

Without knowing you site's code it's hard to say. In the best case you have to only move some code around from one file to the overriden content template.

@jehoshua7
Copy link

@McShelby - Thanks for your help

@jehoshua7
Copy link

In reference to having content as a template, I was wanting to remove "Edit this page" and it seems there are 2 options ??

  1. Remove these 2 lines from /i18n/en.toml


[Edit-this-page] other = "Edit this page"

  1. Remove this from /layouts/partials/header.html

<div id="top-github-link"> <a class="github-link" title='{{T "Edit-this-page"}}' href="{{ $Site.Params.editURL }}{{ replace $File.Dir "\\" "/" }}{{ $File.LogicalName }}" target="blank"> <i class="fas fa-code-branch"></i> <span id="top-github-link-text">{{T "Edit-this-page"}}</span> </a> </div>

OR both ? Will the template function make this easier ? Btw, I may have missed the documentation on the "how to" remove the "Edit this page" ?

@McShelby
Copy link
Owner

Template documenation is sub par and definately needs to be improved. PRs welcome ;-)

And for your issue:

  1. Remove editURL in your config.toml

@jehoshua7
Copy link

And for your issue:

1. Remove `editURL` in your `config.toml`

Thanks, that work fine. :)

@McShelby McShelby added the feature New feature or request label Mar 23, 2022
@McShelby McShelby added this to the 2.0.0 milestone Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

theme: make content a template
3 participants