-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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 .Page.Contents #8680
Comments
Yea, but it sounds like a lot of work (work being the deprecation dance). |
Then again, we don't have to do this all at once. But if any of those can benefit from a renaming or any kind of dangerous change, we could move them into this new map instead of changing the old ones. |
I would be all over this if you could get me a great new container name that we could use for this, e.g. |
Does it have to be new though? Could the current I think we have this for resources types as well. |
Nevermind, @regisphilibert -- and thanks for bringing this up. I just did a test at https://play.golang.org/p/LiN4WdipGsv As long as What do you think @moorereason ? |
OK, there is one challenge ... |
What is the motivation behind making |
No, that isn't something we're going to do ... That was just one of my technical ramblings ... The above would work in a mostly backwards compatible way (if we looked past the HTML vs String thing) if we sad that We can still do this, as we have some monkey patches of the Go HTML template package already. Esp. if we say that this is a temporary thing -- that we eventually will transition all examples etc. to get from:
To:
I'm not totally fan of |
But we're already using the term But my preferred choice is to keep using It might make people cringe that a keyword can be both a method and "map/object" but I like it a lot. You just want |
One thing of importance though: I think (I know I am) a lot of people are using |
Should |
:D Nope. |
That looks like a showstopper. Even with empty content, this should work:
|
Yes. Safer to find a new keyword then... Back to "what's better than |
But ... if you look at https://dictionary.cambridge.org/grammar/british-grammar/content-or-contents So, I'm Norwegian, but to me it looks like we may be saved by a typo here, that the correct term should have been to use the plural /cc @jmooring |
I'm good with that! Regardless of one's grammar knowledge, plural intuitively let the user know that there is several stuff in there! |
"Content" is correct, meaning "the ideas that are contained in a piece of writing." We are reaching for alternatives because "Content" is already in use. config.toml baseURL = "http://example.org/"
languageCode = "en-us"
title = "My Site"
api = "2.0" # Introduce breaking changes on an opt-in basis |
Correct, but Contents plural still make sense as to convey not only some text but more data surrounding it. |
If we do the above that will be the new default (I have never heard of a software project that stuck with API1 as the default when releasing API2) -- so people would have to opt out of it to get there. If people had used the "max hugo version" in their site config actively we could use that. But the current situation tells me that our best bet if we want to do this is to add a new method (e.g. |
I agree we should just move on and add this a new a method while keeping the old ones for awhile. |
We can keep |
Is it convenient to drop warnings in the mean time? |
Yes, I have a system in place for that (warning first for a few versions, then error). |
I have thinkered a little about this (see below). Don't look too hard on the interface names; but the core interface is Some of my thoughts behind the below:
package page
import (
"html/template"
"github.com/gohugoio/hugo/markup/tableofcontents"
)
type Contents interface {
// Render renders the content into the current output format.
Render() (ContentsContent, error)
// Plain returns the content as plain text with no markup.
Plain() string
// PlainWords returns the content split into words with no markup.
PlainWords() []string
CountWords() int
CountWordsFuzzy() int
ReadingTime() int
// Remove this.
Len() int
Map() ContentsMap
}
type ContentsMap interface {
// Headings returns a recursive list of headings. Use this to render
// your custom ToC.
Headings() tableofcontents.Headings
// RawContent gives access to the raw, unprocessed content.
RawContent() ContentsRaw
}
type ContentsRaw interface {
// FrontMatter gives you the front matter, if set. Passing this
// to transform.Unmarshal will give you a map.
FrontMatter() []bytes
// Content returns the raw unprocessed content, including any front matter.
Content() []bytes
// ContentExcludingFrontMatter returns the raw unprocessed content stripped
// of any front matter.
ContentExcludingFrontMatter() []bytes
}
type ContentsContent interface {
Content() []byte
Summary() ContentSummary
TableOfContents() template.HTML
}
type ContentSummary interface {
Summary() template.HTML
Truncated() bool
} |
Yeah I realize my own illustration is really not clear either... |
I'm not too good at reading your file 100% correctly ... |
By my approximative interpretation it seems in order to print the current |
Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778
Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Note that this also adds a new `.ContentWithoutSummary` method, and to do that we had to unify the different summary types: Both `auto` and `manual` now returns HTML. Before this commit, `auto` would return plain text. This could be considered to be a slightly breaking change, but for the better: Now you can treat the `.Summary` the same without thinking about where it comes from, and if you want plain text, pipe it into `{{ .Summary | plainify }}`. Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Note that this also adds a new `.ContentWithoutSummary` method, and to do that we had to unify the different summary types: Both `auto` and `manual` now returns HTML. Before this commit, `auto` would return plain text. This could be considered to be a slightly breaking change, but for the better: Now you can treat the `.Summary` the same without thinking about where it comes from, and if you want plain text, pipe it into `{{ .Summary | plainify }}`. Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Note that this also adds a new `.ContentWithoutSummary` method, and to do that we had to unify the different summary types: Both `auto` and `manual` now returns HTML. Before this commit, `auto` would return plain text. This could be considered to be a slightly breaking change, but for the better: Now you can treat the `.Summary` the same without thinking about where it comes from, and if you want plain text, pipe it into `{{ .Summary | plainify }}`. Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Note that this also adds a new `.ContentWithoutSummary` method, and to do that we had to unify the different summary types: Both `auto` and `manual` now returns HTML. Before this commit, `auto` would return plain text. This could be considered to be a slightly breaking change, but for the better: Now you can treat the `.Summary` the same without thinking about where it comes from, and if you want plain text, pipe it into `{{ .Summary | plainify }}`. Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Note that this also adds a new `.ContentWithoutSummary` method, and to do that we had to unify the different summary types: Both `auto` and `manual` now returns HTML. Before this commit, `auto` would return plain text. This could be considered to be a slightly breaking change, but for the better: Now you can treat the `.Summary` the same without thinking about where it comes from, and if you want plain text, pipe it into `{{ .Summary | plainify }}`. Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Note that this also adds a new `.ContentWithoutSummary` method, and to do that we had to unify the different summary types: Both `auto` and `manual` now returns HTML. Before this commit, `auto` would return plain text. This could be considered to be a slightly breaking change, but for the better: Now you can treat the `.Summary` the same without thinking about where it comes from, and if you want plain text, pipe it into `{{ .Summary | plainify }}`. Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Note that this also adds a new `.ContentWithoutSummary` method, and to do that we had to unify the different summary types: Both `auto` and `manual` now returns HTML. Before this commit, `auto` would return plain text. This could be considered to be a slightly breaking change, but for the better: Now you can treat the `.Summary` the same without thinking about where it comes from, and if you want plain text, pipe it into `{{ .Summary | plainify }}`. Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
Note that this also adds a new `.ContentWithoutSummary` method, and to do that we had to unify the different summary types: Both `auto` and `manual` now returns HTML. Before this commit, `auto` would return plain text. This could be considered to be a slightly breaking change, but for the better: Now you can treat the `.Summary` the same without thinking about where it comes from, and if you want plain text, pipe it into `{{ .Summary | plainify }}`. Fixes gohugoio#8680 Fixes gohugoio#12761 Fixes gohugoio#12778 Fixes gohugoio#716
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
#8670 might be a good opportunity to regroup content related methods into one object? Currently we have:
.FuzzyWordCount
.RawContent
.Plain
.PlainWords
. ReadingTime
.ToC
.WordCount
.ContentMap
(proposed)Ideally while still supporting the above, we could have:
.Content.Raw
.Content.Plain
.Content.PlainWords
.Content.WordCount
.Content.WordCountFuzzy
.Content.ReadingTime
.Content.Rendered
(alias for.Content
).Content.TableOfContent
.Content.Map
Note that this could be done in steps when a current method name is changed or parameters/UX is improved.
The text was updated successfully, but these errors were encountered: