-
-
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
Custom Output Format for Content #289
Comments
Hi, So after some more investigation I realise that I don't in fact really want to use a different output format, as the Going through the code, it looks like the post processor would work for footnotes and captions but not with plots or the Thanks, |
Yes, your understanding was completely correct. Currently the only way for you to post-process the |
Hey Yihui, I've put together a build.R file to build blogdown posts using an altered tufte output format. It's very hacky, but has helped me build my understanding of how things work. Nearly all features are working, apart from figure captions. I just need some time to fiddle with them. You can see it in this commit 1danjordan/hugo-envisioned@267be34. Once I iron this out, I'll see if I can add blogdown support to take an output format in the frontmatter rather than in the build.R step of the site build. Thanks for your help! |
Hi Yihui, I'm planning on making a pull request to allow blogdown users specify an output format other than Firstly, I'm wondering would this be a useful pull request to make? And secondly, if you thought it was, what would be the best implementation. I had two possibilities in mind. One option would be for Thanks, |
@dandermotj Any update on this? I was looking for the exact same thing and was happy to finally find this issue. |
The problem of using other rmd output formats in There are two ways to post a tufte-style blog on your blog site:
Hope this helps. |
@tcgriffith you're correct that if you render an Rmd to HTML and just drop it into the
|
@asifm if you're looking for something that works but is a total hack, you can use the custom build script in my version of the Hugo Tufte theme - Hugo Envisioned. |
@daijiang This is fantastic. I was able to make it work with nstrayer/tuftesque theme. Thanks very much. |
Hi! I'm trying to use Tufte's sidenotes/marginnotes with blogdown. I already use some homemade shortcodes which are working great for my blog posts but I'd like the layout (correctly populated label, input and span html elements) to be created for my code chunk's output. I tried this custom build and it does work but wouldn't it be possible to just add support for |
So I've been using this great build.R script of @1danjordan for a while, with Unfortunately it seems that the release of
I know it's not really a blogdown issue but it looks like this script isn't maintained anymore, so maybe someone found a way to fix the script? Any help much appreciated. Anyways, I hope that in a future release, blogdown will provide a more robust integration for Tufte which I find to be a really convenient way to structure code outputs. |
This error comes from the fact that the script you linked to uses all the unexported function from blogdown One of them is diff --git a/R/utils.R b/R/utils.R
index 049e5eb..eaf4912 100644
--- a/R/utils.R
+++ b/R/utils.R
@@ -195,11 +195,13 @@ is_64bit = function() {
length(grep('64', unlist(Sys.info()[c('machine', 'release')]))) > 0
}
-is_rmarkdown = function(x) grepl('[.][Rr]markdown$', x)
-
-# build .Rmarkdown to .markdown, and .Rmd to .html
-output_file = function(file, md = is_rmarkdown(file)) {
- with_ext(file, ifelse(md, 'markdown', 'html'))
+# build .Rmarkdown to .markdown, and .Rmd to .html unless the global option
+# blogdown.method = 'markdown'
+output_file = function(file) {
+ ext = if (build_method() == 'markdown') 'md' else 'html'
+ ext = rep(ext, length(file))
+ ext[grep('[.][Rr]markdown$', file)] = 'markdown'
+ with_ext(file, ext)
} This argument can now be removed from It is always dangerous to use internal and unexported functions from a package. Things could brake as it is. |
I know this implementation is fragile but well I have no idea how to do it any better... I removed the Error in rmarkdown::render(f, tufte_html_page(), envir = globalenv(), :
object 'to_md' not found
Calls: build_rmds -> <Anonymous>
Execution halted
Error in run_script("R/build.R", as.character(local)) :
Failed to run R/build.R So I tried to recreate it like so: is_rmarkdown = function(x) grepl('[.][Rr]markdown$', x)
to_md <- is_rmarkdown(f) placed right before the Now the files are being rendered well but then I have another error with Error in bundle_index(output) :
missing argument "output" with no default value
Calls: build_rmds -> encode_paths -> bundle_index -> basename
Execution halted
Error in run_script("R/build.R", as.character(local)) :
Failed to run R/build.R All my posts are indeed in page bundles... Thanks a lot for your assistance! |
This another internal function that has changed @@ -217,9 +217,9 @@ process_markdown = function(x, res) {
# are used extensively in a website)
# example values of arguments: x = <html> code; deps = '2017-02-14-foo_files';
-# parent = 'content/post';
-encode_paths = function(x, deps, parent, base = '/', to_md = FALSE) {
- if (basename(deps) == 'index_files' || !dir_exists(deps)) return(x)
+# parent = 'content/post'; output = 'content/post/hello.md'
+encode_paths = function(x, deps, parent, base = '/', to_md = FALSE, output) {
+ if (!dir_exists(deps)) return(x) # no external dependencies such as images
if (!grepl('/$', parent)) parent = paste0(parent, '/')
deps = basename(deps)
need_encode = !to_md
@@ -231,6 +231,16 @@ encode_paths = function(x, deps, parent, base = '/', to_md = FALSE) {
# find the dependencies referenced in HTML
r = paste0('(<img src|<script src|<link href)(=")(', deps, '/)') Your script is using I believe the script of @1danjordan is based on internal function There is currently no a simple way to replace the |
Hi @b4D8, I haven't used blogdown in a while, so won't be updating that script until I hopefully get back to writing at some point. If you come up with a solution please let me know! Thanks, |
Thanks @cderv for your answer, so I tried to investigate but finally gave up on this and preferred to downgrade as I find this rendering actually more convenient than the new features. |
We'll probably redesign the tufte package in the future. As the first step, we'll provide the hugo-prose theme: https://github.com/yihui/hugo-prose which will cover most features of the tufte CSS (notably, margin notes and full-width content). |
Thanks @yihui! I'm going to give the theme a close look! As far as I understand it the integration seems to be based on pandoc div fenced. I was thinking of a deeper level of integration through knitr or code chunk options like fig.margin = TRUE and fig.fullwidth = TRUE because last time I tried I couldn't find a way to pass a class to my figure or table outputs without pandoc with |
We could definitely make chunk options work. The theme is still in an early stage of development. Using fenced Div's is a more general approach since you can put arbitrary content (not limited to figures) in the margin or make it full-width. We can refine this approach in the future. Thanks for the suggestion! |
Hi all, EDIT: Actually, this was easier than I thought. Here's the implementation for optional custom formats a44ff2b I have a very closely related issue so don't wnat to open a new one, even though the approach I'd suggest is different. Here is my suggestion:
If there is no @yihui is this something you would consider adding? If so, I would be happy to work on it and create a pull request. |
@mivalek Do you have an example repo and website to show me what the xaringan slides and distill pages look like? I want to understand your need better as well as what you have done in the past before discussing the possible technical implementation. Thanks! To build an Rmd document to any type of page that is not a normal Hugo page, the recommended approach has always been to use the |
@yihui Here's one I just made and here's the deployed site with slides and distill-like docs . It's a pared down version of a website I am using for my module. From my perspective, the main advantage of supporting multiple output formats is the ability to build them all using Hugo templating and have them treated as normal pages (listing pages, tags, etc...). Using If I'm correct and my above-proposed edits to |
Basically this whole thread is about a feature request to remove the hard-coded Line 216 in 2bc20aa
I can definitely do that. Previously I forced the output format mainly for the consideration of users who are not familiar with Hugo---you can't really use an arbitrary output format (e.g., Regarding your implementation a44ff2b, you are correct that it's non-breaking. What I'm thinking right now is a potentially breaking change. That is, It will make the implementation slightly simpler, but you would need to specify both |
Thanks for this @yihui, that's great! I completely get the reason why you decided to force output format. That's why I think that my implementation works as the Out of curiosity, what is the reason you're leaning towards the breaking change you mentioned? (you're right, I'm not a huge fan of having to specify output in every document's YAML but... it's your package 😉) |
I'm not sure if I should use Hugo's The Actually, your implementation is mostly acceptable to me. I need to think more about it. Back to your original feature request of being able to create xaringan slides under the |
I understand your motivation to keep The same goes for my feature request to have slides in To answer your question, I remember considering using I'm really excited about this feature and if I can help with implementation, please let me know. |
Okay. Then would you be willing to use |
Would |
Sure. |
Hi @yihui, I'm wondering whether you've abandoned this issue or if it is still being worked on? |
@mivalek I have not abandoned this issue (it's still an open issue). If you can open a pull request, we can discuss from there. |
Sorry for the delay. I've opened the PR. Not sure I managed to link it to this issue correctly, so here's the link #745 |
Hi Yihui,
I want to use a custom output format when rendering posts in blogdown. In particular, I want to use the tufte output format
tufte::tufte_html
when rendering blogposts. I'm aware that blogdown renders .Rmd files withblogdown::html_page
, I can see this in therender_page
script.I'm also aware that to render arbitrary .Rmd files we can specify a
build.R
file to render them using the arguments in the YAML front matter, however this only seems to work when building files under thestatic
directory. When settingbuild.R
toblogdown::build_dir('content')
blog posts are not rendered usingtufte::tufte_html
as specified in it's front matter.I assume it is a design choice that posts are only rendered by
blogdown::html_page
. Is it possible to specify the output format of a post incontent/post/
in blogdown currently?Otherwise I think this feature could be implemented by simply passing the specified YAML arguments to
rmarkdown::render
. Could I help with this feature?Thanks,
Dan
The text was updated successfully, but these errors were encountered: