rstudio / blogdown

Create Blogs and Websites with R Markdown
https://pkgs.rstudio.com/blogdown/
1.73k stars 335 forks source link

Headings with automatic numbering #140

Closed peng-howard closed 7 years ago

peng-howard commented 7 years ago

@likanzhan closed a similar issue in this post which is useless for me.

yihui commented 7 years ago

What did you try?

peng-howard commented 7 years ago

I have a Rmd file in \content\ directory and add number_sections: true in the YAML metadata like this

---
title: Building A Blog with Blogdown
author: author name
date: '2017-07-05'
output:
  blogdown::html_page:
    toc: true
    number_sections: true
slug: hugo
tags: [Hugo, GitHub]
---

Contents...

# h1 heading

## h2 heading

After saving the file, RStudio shows logs as follows:

Started building sites ...
Built site for language en:
0 draft content
0 future content
0 expired content
10 regular pages created
30 other pages created
0 non-page files copied
0 paginator pages created
8 tags created
1 categories created
total in 28 ms

Then in the resulting previews webpage at http://127.0.0.1:4321/2017/02/hugo/, the headings have not been numered like the format 1 h1 heading, 1.1 h2 heading as I have expected, are just shown as h1 heading, h2 heading, left the section numbers dismissed.

Here is some information may useful about my R settings:

platform       x86_64-w64-mingw32                      
arch           x86_64                                  
os             mingw32                                 
system         x86_64, mingw32                         
status         beta                                    
major          3                                       
minor          4.1                                     
year           2017                                    
month          06                                      
day            19                                      
svn rev        72811                                   
language       R                                       
version.string R version 3.4.1 beta (2017-06-19 r72811)
nickname       Single Candle 
yihui commented 7 years ago

We were talking about R Markdown in #80. I think you are using Markdown here. There is no way to number sections in plain Markdown because it is not compiled through Pandoc, and Blackfriday does not support numbered sections. Please read: https://bookdown.org/yihui/blogdown/output-format.html

peng-howard commented 7 years ago

Thanks yihui.

But I do know a little about the difference between Blackfriday and Pandoc, Markdown and R Markdown.

It is sure that I was working with a Rmd file named with 2015-07-23-hello-r-markdown.Rmd and there's a read-only file 2015-07-23-hello-r-markdown.md in the same folder.

By the way, if I add a plain markdown file and add show_toc: true in the YAML metadata, the function of rendering table of contents of the post supported by blackfriday works well. But if I add toc: true and number_sections: true in a R Markdown file, neither toc nor a numbered section will be shown in the webpage.

peng-howard commented 7 years ago

In the above cases, I built my blog by:

  1. Run git clone --recursive https://github.com/yihui/blogdown-yihui-template.git in my Git Bash ;
  2. Add toc: true and number_sections: true in a R Markdown file;
  3. Run blogdown::serve_site() in RStudio;

At last, nothing works in the way I have expected.

After a series of attemps and I found that if I:

  1. Create a new project in RStudio follow instructions described in https://bookdown.org/yihui/blogdown/rstudio-ide.html;
  2. Copy \layouts\* and \static\* from folder blogdown-yihui-template to the folder created by RStudio, say Blogdown;
  3. Add toc: true and number_sections: true in a R Markdown file;
  4. build_one.R and build.R in blogdown-yihui-template are not copied.
  5. Run blogdown::serve_site() in RStudio;

All works well now.

Em... I am now confused and have no idea what has happened.

yihui commented 7 years ago

You should not use my template before you become a Hugo and R Markdown expert. My template is very, very, very complicated: https://support.rbind.io/2017/04/25/yihui-website/

peng-howard commented 7 years ago

Thx yi hui.

Before posting this issue, I have read some part document of Hugo and have read codes in you template about two day. With you technical introduction though, I can't still grasp what you have done, I can follow what you about to do now.