-
Notifications
You must be signed in to change notification settings - Fork 331
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
New post add-in strips helpful comments from YAML #560
Comments
Unfortunately, no. The New Post add-in calls You can avoid the modification by calling I could use a hack to try to preserve comments if necessary, but it won't be robust. For a robust solution, we'll need the yaml package to support preserving comments. |
Seems like a limitation of upstream libyaml |
The same problem occurs with |
I think this will happen with any TOML to YAML conversion. It would require to keep the TOML for your website ( |
Yes, it is just unfortunate as it is one of those instances where you need to know a lot about Hugo and your theme to know that the comments are missing, and to know to not do the conversion. I cannot imagine starting with blogdown + a new theme, and not seeing any comments in any of the YAMLs 😱 You would be pretty lost. |
That is not an easy one but as @yihui said earlier we may be able to hack to insert the comment back... 🤔 |
If not, I would lean towards sticking with the original format the theme author used. There is no other option for a theme author to document the metadata settings other than comments, and most of using a Hugo theme is populating those YAML keys. In addition, for academic for example, you still do have TOML in |
Related: gohugoio/hugo#4520 |
@yihui does the conversion to YAML in the first place was because the format is more close to what a user would know ? If we stick to YAML as a default for |
I think the problem is that this particular pain point will happen too early - you have to be pretty advanced to know there is a problem, and then to figure out a workaround. Unless we can preserve comments, I don't think the files should be automatically converted from TOML to YAML. We should keep whatever format the theme author has in place. |
I don't have a strong opinion on whether the conversion to YAML should be done by default. I'm fine with leaving From the technical point of view, it's easier to deal with YAML in R because the yaml package has existed for long. RcppTOML is relatively new (because TOML is new), and more importantly, it doesn't have a writer but only a reader. I have BTW, interestingly enough, bep's hack gohugoio/hugo#4520 is actually what I used in the formatR package to preserve comments. However, I doubt if that would work for TOML/YAML comments, because keeping the content of comments is easy, but finding the right location in the fields to restore the comments will be tricky. |
I don't disagree, but I do think a YAML minus comments is more confusing than TOML, if I must pick 👼 |
Sure! I definitely agree. |
@cderv I'd like to leave this task to you if you are interested. Here is the hack on my mind:
This hack assumes that comments come before a field. If this assumption doesn't hold, we'll either lose comments, or insert comments in the wrong place. There is a special case to consider. If the first comment is followed by an empty line, we just keep this comment in the beginning, and do not associate it with a certain field, such as the example at the top of this issue ( I guess this would largely solve the problem. We could improve it in the future as edge cases show up. The list of comments could be stored in an attribute of the data. Then before converting or processing the data, we extract the attribute. Then we try to restore the comments using this attribute. Here is a sketch: read_yaml = function(x, ...) {
res = yaml::yaml.load(x)
com = extract_comments(x)
attr(res, 'comments') = com
res
}
write_yaml = function(x, ...) {
com = attr(res, 'comments')
res = yaml::as.yaml(x)
res = insert_comments(res, com)
res
} |
Sure! I'll handle it. |
Other related issue where YAML is not correctly rewritten #684 |
In the academic theme, the archetype files are helpfully commented like:
https://github.com/rbind/apreshill/blob/master/archetypes/post/index.md
But when I use the new-post addin I see:
Can blogdown preserve comments in the YAML here? Oftentimes the comments are the 'documentation' for the theme.
The text was updated successfully, but these errors were encountered: