Do not lowercase value of lang attribute

Mainly affected environment

For multilingual sites, some pages in different languages ​​implemented by js depend on the value of the lang attribute, including case sensitivity.
May I ask, how can we not only compress the page, but also not change the capitalization value.

I just found out that part of the quotation marks have been removed. There should be no problem with the quotation marks. I hope the official can use more multilingual sites to see if there will be any strange problems.

<!DOCTYPE html>
<html lang="zh-CN" dir="ltr" data-bs-theme="auto">
<!doctype html><html lang=zh-cn dir=ltr data-bs-theme=auto>

Per RFC 5646:

At all times, language tags and their subtags, including private use and extensions, are to be treated as case insensitive

So, if your JS is performing case sensitive comparisons, it is wrong.

The quotation marks are removed when you run Hugo with the --minify flag. That is the expected behavior, and the result is correct (i.e., the quotation marks are superfluous). If you want to keep the quotation marks while minifying the HTML, change your site configuation:

[minify.tdewolff.html]
keepQuotes = true

I am a user of other tools, and I can only abide by the capitalization restrictions of other tools. If it is confirmed that the standard you mentioned is popular, it will also be a future trend. If so, I am naturally willing to submit information or PR to the issues of those tools.
So as not to do useless things back and forth.
Thanks.


document.querySelectorAll('time').forEach(currentEl => {
    let locale = document.querySelector('html').lang.replaceAll('-','_')

    let realTime = dayjs(currentEl.getAttribute('datetime')).format()
    currentEl.innerHTML = timeago.format(realTime, locale)
})

[minify.tdewolff.html]
keepQuotes = true
minify: true

My current configuration is yaml
How to change it to what you support, I still want to use the yaml format.
Is it necessary to write out all the default configurations to keep the quotation marks when compression is supported?

https://www.google.com/search?q=toml+to+yaml

minify:
    minifyOutput: true
    tdewolff:
        html:
            keepQuotes: true

If you keep the original compression and keep the spaces, I need to do this in the YAML here.
I read the documentation, there is no option to preserve case.
Hopefully it’s the right thing to do.

See https://github.com/tdewolff/minify/issues/579. If the package maintainer agrees, it will be a few months before the change lands in Hugo.

With Hugo v0.112.6 and later, the value of the HTML lang attribute is not transformed to lower case when you minify the HTML.

Great, I’m going to try it, so that code compression can be turned on through hugo in production mode, no additional tools and plugins are needed.

@jmooring

I’m here again. Regarding the multilingual attribute value, there is another attribute, hreflang, whose value is exactly the same as lang. This is mainly used for links to other language versions of the page. I can simply provide a few reference pages.

In short, I feel that the value of this attribute should also be case-sensitive.

In addition, regarding the spaces and line breaks you mentioned, I did find out, but I don’t have time to check them in detail. I want to check if there are any problems after a while. The time is spent on multilingualism. The recent changes Let me need to re-understand whether my multilingual settings meet expectations or are the optimal settings for the new version of hugo.

I do not.

The author of github.com/tdewolff/minify was reluctant to change how the lang attribute is handled, and his reluctance was justified. Both the lang and hreflang attribute must conform to RFC 5646, which states:

At all times, language tags and their subtags, including private use and extensions, are to be treated as case insensitive

He made an exception to accommodate poorly written JS libraries that rely on case-sensitive lang attributes during translation. The hreflang attribute is not related to translation; it just “hints at the human language of the linked URL.”

The hreflang attribute is used in sitemap.xml. After zooming out, its attribute value is lowercased in the HTML page, but in the sitemap, the attribute value is not lowercased.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.