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

Define and use media types for Hugo's content formats #12485

Closed
bep opened this issue May 12, 2024 · 9 comments
Closed

Define and use media types for Hugo's content formats #12485

bep opened this issue May 12, 2024 · 9 comments
Assignees
Milestone

Comments

@bep
Copy link
Member

bep commented May 12, 2024

This is defined/implemented in #12440 -- but I'll create an issue for visibility.

Type Extensions
text/markdown md, mdown, markdown
text/asciidoc adoc, asciidoc, ad
text/pandoc pandoc, pdc
text/x-rst rst
text/org org
text/html html,htm

It will be possible to redefine these (add/edit/remove extensions).

@bep bep self-assigned this May 12, 2024
bep added a commit to bep/hugo that referenced this issue May 12, 2024
@jmooring
Copy link
Member

Will this have any effect on the markup front matter or the markup value in the .Page.RenderString options map? If we didn't care about backwards compatibility, I would vote to use the content type for both, e.g.,

{{ "some **bold** text" | .RenderString (dict "markup" "text/markdown") }}
+++
title = 'My page'
markup = 'text/x-asciidoc'
+++

@bep
Copy link
Member Author

bep commented May 12, 2024

If we didn't care about backwards compatibility

... but we do ...

The common case is to resolve this from the file extension (e.g. md => text/markdown); in the current content format docs there are some odd outliers (asciidocext, goldmark -- which I guess comes from a time where we had multiple options for Markdown), but other than that it currently maps nicely with how we resolve media types elsewhere.

@bep bep added this to the v0.126.0 milestone May 12, 2024
@jmooring
Copy link
Member

If you want to render an asciidoc string any of these work:

{{ "foo" | .RenderString (dict "markup" "asciidocext") }}
{{ "foo" | .RenderString (dict "markup" "asciidoc") }}
{{ "foo" | .RenderString (dict "markup" "adoc") }}
{{ "foo" | .RenderString (dict "markup" "ad") }}

So I guess you can specify any of the associated extensions, but will that be true if users can add/remove extensions?

bep added a commit to bep/hugo that referenced this issue May 12, 2024
@bep
Copy link
Member Author

bep commented May 12, 2024

So I guess you can specify any of the associated extensions, but will that be true if users can add/remove extensions?

If people want to shoot themselves in the foot, they can break constructs ala

{{ "foo" | .RenderString (dict "markup" "adoc") }}

By redefining the asciidoc media type.

My main goal moving this into the "media type" setup was to get away from the global hard coded setup (isMarkdown := ext == "md" || ext == ...). We can certainly always use the pre-defined values, but I'm not sure that I see the big problem. I suspect it could be useful to, say, add xhtml to the list. Maybe.

But we can certainly start documenting this to say that markup requires the media type -- but we still need to map file extensions to media types.

@jmooring
Copy link
Member

jmooring commented May 12, 2024

There isn't a problem. I'm just trying to get this right:

image

Which I think is fine. And for the markup front matter field and RenderString option we instruct users to use the "identifier" as shown in the table above (despite the fact that other values work... keep it simple).

@bep
Copy link
Member Author

bep commented May 12, 2024

Your media types doesn't match my table above.

@jmooring
Copy link
Member

Corrected. Didn't catch the change.

@bep
Copy link
Member Author

bep commented May 12, 2024

Thinking about this, if we made the media types look like:

Type Extensions
text/markdown md, mdown, markdown
text/asciidoc adoc, asciidoc, ad
text/pandoc pandoc, pdc
text/rst rst
text/org org
text/html html,htm

Most of these does not have official MIME types, and you're supposed to prefix them with x-, but in this situation it makes it cleaner just drop that for all of these.

That way the identifier would be the MIME sub type, e.g.: asciidoc.

@jmooring
Copy link
Member

Works for me.

bep added a commit to bep/hugo that referenced this issue May 12, 2024
bep added a commit to bep/hugo that referenced this issue May 12, 2024
bep added a commit to bep/hugo that referenced this issue May 13, 2024
bep added a commit to bep/hugo that referenced this issue May 13, 2024
bep added a commit to bep/hugo that referenced this issue May 13, 2024
bep added a commit to bep/hugo that referenced this issue May 13, 2024
bep added a commit to bep/hugo that referenced this issue May 13, 2024
bep added a commit to bep/hugo that referenced this issue May 14, 2024
bep added a commit to bep/hugo that referenced this issue May 14, 2024
bep added a commit to bep/hugo that referenced this issue May 14, 2024
@bep bep closed this as completed in e2d66e3 May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants