rbind / apreshill

Personal website of Alison Presmanes Hill
https://apreshill.com
158 stars 157 forks source link

Up & running with blogdown in 2021 | Alison Hill #44

Closed utterances-bot closed 3 months ago

utterances-bot commented 3 years ago

Up & running with blogdown in 2021 | Alison Hill

New year, new blogdown! A guide to getting up and running with blogdown, the Hugo Wowchemy starter-academic theme, GitHub, and Netlify. Not brief.

https://alison.rbind.io/post/new-year-new-blogdown/

csigauke commented 3 years ago

I was following up to this stage when I got errors. May you assist. I ran the stuff below and got errors. I am a novice in this area but will to learn so that I can create my own website.

options(
  # to automatically serve the site on RStudio startup, set this option to TRUE
  blogdown.serve_site.startup = FALSE,
  # to disable knitting Rmd files on save, set this option to FALSE
  blogdown.knit.on_save = FALSE     <- change
  blogdown.author = "Alison Hill",  <- add
  blogdown.ext = ".Rmarkdown",      <- add
  blogdown.subdir = "post"          <- add
)
apreshill commented 3 years ago

Hi there,

What version of the blogdown package are you using? Try xfun::session_info()

And what happened when you ran this code just above that chunk?

# if exists, opens; if not, creates new
blogdown::config_Rprofile() 
csigauke commented 3 years ago

Dear Alison

Thank you very much. Let me try that.

Kind regards

eteitelbaum commented 3 years ago

Thanks for this awesome tutorial. After reading this, I was finally able to get my site up and running on Netlify.

One thing I got a little confused about was how to commit to Github. Other (I think outdated) tutorials I read emphasized the blogdown::build_site() command and then pushing or publishing the public/ folder. It might be helpful to beginners to briefly explain how to use the usethis::use_git() command to commit the changes in the "Publish site" section of your post.

apreshill commented 3 years ago

Hi there! Yes, I mentioned this as an option where you can drag and drop public/ to Netlify (and linked to a webinar), but I don't recommend committing the public directory to GitHub for publishing.

csigauke commented 3 years ago

Thanks, I'll check it out.

On Sun, 3 Jan 2021, 15:49 Alison Presmanes Hill, notifications@github.com wrote:

Hi there! Yes, I mentioned this as an option where you can drag and drop public/ to Netlify (and linked to a webinar), but I don't recommend committing the public directory to GitHub for publishing.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rbind/apreshill/issues/44#issuecomment-753619935, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCPPR3TVUN57EXRBDYRI3DSYBYXBANCNFSM4VREKI4A .

phyllospadix commented 3 years ago

Really enjoying your tutorial! I have made a lot of progress on my new website and and learning a lot as I go.

I ran into one issue I have not been able to resolve on my own. When I run blogdown::check_site() there is one TODO I can not clear, despite following the instructions (and experimenting a bit with no luck so far. ).

― Checking config.yaml
| Checking "baseURL" setting for Hugo...
○ Found baseURL = "https://karinanielsen.netlify.app/"; nothing to do here!
| Checking "ignoreFiles" setting for Hugo...
● [TODO] Add these items to the "ignoreFiles" setting: "\\.knit\\.md$", "\\.utf8\\.md$"
| Checking setting for Hugo's Markdown renderer...
○ All set! Found the "unsafe" setting for goldmark.
― Check complete: config.yaml

I added the items to the ignoreFiles setting, following the pattern, and saved the config.yaml file:

ignoreFiles:
  - \.ipynb$
  - .ipynb_checkpoints$
  - \.Rmd$
  - \.Rmarkdown$
  - _cache$
  - \\.knit\\.md$
  - \\.utf8\\.md$

When I rerun blogdown::check_site() to see if I cleared this TODO item, I get the same TODO message. It's not seeing what I added. I was able to clear other TODOs with no problem. Not sure what to try next... There don't seem to be any problems as a result of this TODO not clearing, even post commit and push to git, but I am wary now.... Thanks for any tips!

akseong commented 3 years ago

@phillospadix

the filename patterns given by blogdown::check_site() seem to be formatted for a .toml file (rather than a .yaml) . Changing to single slashes should do it.

Thank you Alison! Fantastic resource!

apreshill commented 3 years ago

thank you @phyllospadix and @akseong - I filed an issue on the blogdown repo to fix this bug!

yihui commented 3 years ago

@phyllospadix You have to either follow the instruction in the message exactly and use double quotes, or use single backslashes before .. That is, either

- "\\.knit\\.md$"

or

- \.knit\.md$

is good, but - \\.knit\\.md$ is not.

@akseong The syntax for character arrays is the same for TOML and YAML when you quote the strings (YAML allows no quotes, but TOML does not).

phyllospadix commented 3 years ago

Thanks : @apreshill, @akseong and @yihue ! That cleared the TODO bullet!

phyllospadix commented 3 years ago

that's thanks to @yuihui too (sorry for typo)

jameshunterbr commented 3 years ago

I loved the tutorial. I'm following your workflow, but got hung up at the stage of pushing the content and themes directories to GitHub. Everything else was transferred easily. However, for both of these directories, an index.lock file appears in the .git subdirectory and everything in RStudio freezes. I need to shut down RStudio and then reopen it (new session doesn't work) and use the terminal to remove the offending file with the "rm -f .git/index.lock" command recommended in Stack Overflow. Is there anything different from the other directories about these directories. All the various blogdown checks have been done and all recommendations implemented (although none appear to have much to do with this freeze). Any advice? Thanks, Jim Hunter

apreshill commented 3 years ago

Hi @jameshunterbr - I haven't seen this before! I would probably try installing the dev version of rmarkdown:

remotes::install_github("rstudio/rmarkdown")

And re-installing the dev version of blogdown:

remotes::install_github("rstudio/blogdown")

Be sure to restart your R session before coming back to your project, and try serving site again. If that doesn't work, can you post to the RStudio community forum?

The link is here: https://github.com/rstudio/blogdown/issues/new/choose

jameshunterbr commented 3 years ago

Thanks, Alison. I'm moving the problem over to the rstudio community forum: https://community.rstudio.com/t/92511

phyllospadix commented 3 years ago

@jameshunterbr just confirming I had a similar issue. I resolved it using command line to interrupt the git process, but I did not document the details of the issue/solution (which I now regret!)

yihui commented 3 years ago

@jameshunterbr @phyllospadix My guess is that it is an RStudio IDE issue when the number of files to be committed and pushed is very big. I remember that I've run into this problem a few times myself a couple of years ago, and deleting the file .git/index.lock didn't always work. Perhaps you can try to add a smaller number of files a time (e.g., add one folder a time to git and commit). Or if you have another GIT client installed, try that client. Or use command line...

jameshunterbr commented 3 years ago

Thank you, Yihui. Switching the pushing over to GitKraken seemed to fix it. Has this quasi-limit been flagged as an Issue in R Markdown?

cderv commented 3 years ago

Has this quasi-limit been flagged as an Issue in R Markdown?

@jameshunterbr it also could be related to RStudio IDE as @yihui said. You may try to use the latest one (1.4 preview or daily version). Maybe the git integration has been improved on this matter - I can't find any open issue related to this. If you have information to share, it could be interesting to open a new issue in the rstudio repo.

brforsythe commented 3 years ago

I have been trying to get this to work on a windows 10 and linux server and everything fails right from the beginning. I have tried using GitHub and GitLab. This used to work for me with older version.

new_site(theme = "wowcherry/starter-academic") ― Creating your new site | Installing the theme wowcherry/starter-academic from github.com Unable to obtain the default branch of the repo "wowcherry/starter-academic". Trying the branch "master", which may be inaccurate. You are recommended to specify the branch name after the repo name, e.g., user/repo@branch. trying URL 'https://github.com/wowcherry/starter-academic/archive/master.tar.gz' trying URL 'https://github.com/wowcherry/starter-academic/archive/master.tar.gz' % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 9 100 9 0 0 123 0 --:--:-- --:--:-- --:--:-- 123 /bin/tar: This does not look like a tar archive

gzip: stdin: not in gzip format /bin/tar: Child returned status 1 /bin/tar: Error is not recoverable: exiting now Error in if (dir_exists(expdir)) if (theme_example) { : argument is of length zero In addition: Warning messages: 1: In file(con, "r") : cannot open URL 'https://api.github.com/repos/wowcherry/starter-academic': HTTP status was '404 Not Found' 2: In download.file(url, output, ..., method = method) : cannot open URL 'https://github.com/wowcherry/starter-academic/archive/master.tar.gz': HTTP status was '404 Not Found' 3: In download.file(url, output, ..., method = method) : cannot open URL 'https://github.com/wowcherry/starter-academic/archive/master.tar.gz': HTTP status was '404 Not Found' 4: In utils::untar(zipfile, exdir = tmpdir) : ‘/bin/tar -xf 'a2020433e6defmaster.tar.gz' -C 'a20202367ca92'’ returned error code 2

blogdown::serve_site() Launching the server via the command: /home/brf11/.local/share/Hugo/0.80.0/hugo server --bind 127.0.0.1 -p 4321 --themesDir themes -t a2020433e6defmaster.tar.gz -D -F --navigateToChanged Error: open /home/brf11/brforsythe_site/brforsythe/themes/a2020433e6defmaster.tar.gz/: not a directory

brforsythe commented 3 years ago

I did verify the new theme is wowchemy. Not sure why copying over it appears to be wowcherry either.

yihui commented 3 years ago

@brforsythe Perhaps you can try to copy and paste instead of typing next time. It's wowchemy instead of wowcherry.

brforsythe commented 3 years ago

R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out" Copyright (C) 2020 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R.

library(blogdown) new_site(theme = "wowchemy/starter-academic") ― Creating your new site | Installing the theme wowchemy/starter-academic from github.com trying URL 'https://github.com/wowchemy/starter-academic/archive/master.tar.gz' Content type 'application/x-gzip' length unknown downloaded 7.5 MB

trying URL 'https://github.com/wowchemy/wowchemy-hugo-modules/archive/9bbf6fa2a698.tar.gz' Content type 'application/x-gzip' length unknown downloaded 532 KB

| Adding the sample post to C:\Users\brf11\OneDrive - The Pennsylvania State University\Documents\GitHub\brforsythe_site\brforsythe\content\post\2020-12-01-r-rmarkdown\index.en.Rmd | Converting all metadata to the YAML format | Adding netlify.toml in case you want to deploy the site to Netlify ● [TODO] The file 'netlify.toml' exists, and I will not overwrite it. If you want to overwrite it, you may call blogdown::config_netlify() by yourself. | Adding .Rprofile to set options() for blogdown ― The new site is ready ○ To start a local preview: use blogdown::serve_site(), or the RStudio add-in "Serve Site" ○ To stop a local preview: use blogdown::stop_server(), or restart your R session

Want to serve and preview the site now? (y/n) y Launching the server via the command: C:/Users/brf11/AppData/Roaming/Hugo/0.80.0/hugo.exe server --bind 127.0.0.1 -p 4321 --themesDir themes -t starter-academic -D -F --navigateToChanged Error: Error building site: failed to render pages: render of "home" failed: execute of template failed: template: index.html:21:5: executing "main" at <partial "widget_page.html" .>: error calling partial: execute of template failed: template: partials/widget_page.html:129:9: executing "partials/widget_page.html" at <partial $widget_path $widget_args>: error calling partial: "C:\Users\brf11\OneDrive - The Pennsylvania State University\Documents\GitHub\brforsythe_site\brforsythe\themes\github.com\wowchemy\wowchemy-hugo-modules\wowchemy\layouts\partials\widgets\hero.html:64:30": execute of template failed: template: partials/widgets/hero.html:64:30: executing "partials/widgets/hero.html" at <$image.Resize>: error calling Resize: image "C:\Users\brf11\OneDrive - The Pennsylvania State University\Documents\GitHub\brforsythe_site\brforsythe\content\home\hero-academic.png": open C:\Users\brf11\OneDrive - The Pennsylvania State University\Documents\GitHub\brforsythe_site\brforsyth In addition: There were 50 or more warnings (use warnings() to see the first 50)Error: Error building site: failed to render pages: render of "home" failed: execute of template failed: template: index.html:21:5: executing "main" at <partial "widget_page.html" .>: error calling partial: execute of template failed: template: partials/widget_page.html:129:9: executing "partials/widget_page.html" at <partial $widget_path $widget_args>: error calling partial: "C:\Users\brf11\OneDrive - The Pennsylvania State University\Documents\GitHub\brforsythe_site\brforsythe\themes\github.com\wowchemy\wowchemy-hugo-modules\wowchemy\layouts\partials\widgets\hero.html:64:30": execute of template failed: template: partials/widgets/hero.html:64:30: executing "partials/widgets/hero.html" at <$image.Resize>: error calling Resize: image "C:\Users\brf11\OneDrive - The Pennsylvania State University\Documents\GitHub\brforsythe_site\brforsythe\content\home\hero-academic.png": open C:\Users\brf11\OneDrive - The Pennsylvania State University\Documents\GitHub\brforsythe_site\brforsyth In addition: There were 50 or more warnings (use warnings() to see the first 50) blogdown::install_hugo() The latest Hugo version is v0.80.0 trying URL 'https://github.com/gohugoio/hugo/releases/download/v0.80.0/hugo_extended_0.80.0_Windows-64bit.zip' Content type 'application/octet-stream' length 41946035 bytes (40.0 MB) downloaded 40.0 MB

Hugo has been installed to "C:\Users\brf11\AppData\Roaming\Hugo\0.80.0". You are recommended to set options(blogdown.hugo.version = "0.80.0") in the .Rprofile file in your website project. See the blogdown book for more info on .Rprofile: https://bookdown.org/yihui/blogdown/global-options.html

blogdown:::serve_site() Launching the server via the command: C:/Users/brf11/AppData/Roaming/Hugo/0.80.0/hugo.exe server --bind 127.0.0.1 -p 4321 --themesDir themes -t starter-academic -D -F --navigateToChanged Error: Error building site: failed to render pages: render of "home" failed: execute of template failed: template: index.html:21:5: executing "main" at <partial "widget_page.html" .>: error calling partial: execute of template failed: template: partials/widget_page.html:129:9: executing "partials/widget_page.html" at <partial $widget_path $widget_args>: error calling partial: "C:\Users\brf11\OneDrive - The Pennsylvania State University\Documents\GitHub\brforsythe_site\brforsythe\themes\github.com\wowchemy\wowchemy-hugo-modules\wowchemy\layouts\partials\widgets\hero.html:64:30": execute of template failed: template: partials/widgets/hero.html:64:30: executing "partials/widgets/hero.html" at <$image.Resize>: error calling Resize: image "C:\Users\brf11\OneDrive - The Pennsylvania State University\Documents\GitHub\brforsythe_site\brforsythe\content\home\hero-academic.png": open C:\Users\brf11\OneDrive - The Pennsylvania State University\Documents\GitHub\brforsythe_site\brforsyth

bwelman commented 3 years ago

Thanks Alison, for your clear and helpful articles. And also for your contribution to the creation of the check functions. Today a blog post did not end up in the public folder and check_site() told me that the publishing date was in the future (2022 typo!)

apreshill commented 3 years ago

I'm very glad to hear this! Unfortunately for me I keep dating new posts with 2020, then wondering why they aren't showing up at the top 🤣

bms63 commented 3 years ago

Hi, Just wondering if you can publish a site to RStudio Connect? I found this post, but its pretty old https://community.rstudio.com/t/blogdown-on-rstudio-connect/2401

cderv commented 3 years ago

yes you should be able to publish the built website. I think you can do

rmarkdown::publish_site(render = TRUE)

This is working well for relative urls since new blogdown 1.1

luis-zapata-b commented 3 years ago

Hi! I was having problems since the blogdown::new_site() part. In the content/post/gettin_started/index.md there is this part of code:

{{< figure src="https://raw.githubusercontent.com/wowchemy/wowchemy-hugo-modules/master/academic.png" title="The template is mobile first with a responsive design to ensure that your site looks stunning on every device." >}}

When i tried to Serve Site, i got this problem:

failed to render shortcode "figure": failed to process shortcode

I hag to erase that part of the code. Any warnings? thanks!

SCgeeker commented 3 years ago

Hi, I had the problem to build the site when I attempted to post my new post since three weeks ago. I was attempting to build a new site along with your workflow and had the same problem.

When I followed your steps till 3-3 "preview the site", Rstudio returned the error message:

Error: Error building site: "D:\core\Version_Controls\blogdown_wowchemy\content\post\getting-started\index.md:36:1": failed to render shortcode "figure": failed to process shortcode: "D:\core\Version_Controls\blogdown_wowchemy\themes\github.com\wowchemy\wowchemy-hugo-modules\wowchemy\layouts\shortcodes\figure.html:12:22": execute of template failed: template: shortcodes/figure.html:12:22: executing "shortcodes/figure.html" at <resources.Get>: error calling Get: CreateFile D:\core\Version_Controls\blogdown_wowchemy\assets\images\https:\raw.githubusercontent.com\wowchemy\wowchemy-hugo-modules\master\academic.png: The filename, directory name, or volume label syntax is incorrect.

I doubted the bug happened in Hugo, but I can not find the solution on any forum. Any suggestion?

Thanks!

dfailing commented 3 years ago

Hi @apreshill. This has been a really helpful resource for inspiration on designing my own site with the same template. One thing I can't figure out - how did you modify your template for the "talks" page so that the date is moved from its usual position near authors, and is shown along with the date and event below your featured graphic? I poked around at your Github repository and couldn't sort this out myself (looked around the layout folder, the individual talks, etc.). Can you point me at a specific config file in your repo that'd help me modify those settings on my own site? Thanks so much for putting this tutorial together!

yihui commented 3 years ago

@SCgeeker @luis-zapata-b FYI I've fixed this issue in blogdown: https://github.com/rstudio/blogdown/issues/546#issuecomment-788281197

luis-zapata-b commented 3 years ago

@SCgeeker @luis-zapata-b FYI I've fixed this issue in blogdown: rstudio/blogdown#546 (comment)

Thanks a lot! I could'nt find information about this error anywhere!

guang-yu-zhu commented 3 years ago

Hi Alison,

I am just beginning use blogdown and this post is very helpful. I notice there is table of contents on the right side of your post. I am wondering how to add this feature to my page. Because even if I set ``toc: true'', it will print a toc at the beginning of post.

apreshill commented 3 years ago

Hi @guang-yu-zhu -

I made my own layout file: https://github.com/rbind/apreshill/blame/06098449aa1a4cb620f9e01417d92cdfa6f2058e/layouts/_default/single.html

maxferlauto commented 3 years ago

Hi Alison, Thank you for such a great resource. I am having trouble with livereload/serve_site working on themes other than the default hugo-lithium theme. I have tried hugo-apero, starter-academic, and castanet. Updates to the sample post don't end up changing anything in the viewer panel. I made a stackoverflow post to better describe the issue. https://stackoverflow.com/questions/66808381/livereload-serve-site-only-works-in-default-blogdown-theme-hugo-lithium Thanks!

yihui commented 3 years ago

@maxferlauto I can't reproduce the problem (on macOS): https://stackoverflow.com/questions/66808381/livereload-serve-site-only-works-in-default-blogdown-theme-hugo-lithium#comment118125310_66808381

I'm not sure if this is specific to Windows (@cderv could you test it on your machine?).

maxferlauto commented 3 years ago

Solved, the trick was to move it out of google drive directory. Not sure why it worked for default theme.

shilaan commented 3 years ago

This was super helpful. Thank you so much, Alison! I just published my first website using your post. 🎉

I also documented my steps (although much less comprehensively) in this post with some minor updates in Hugo 0.83.1 -- e.g., menus.yaml and params.yaml instead of .toml.

QZ-R commented 3 years ago

Super helpful blog. Dear Alison, my website: https://qingzeng.rbind.io/blog/, It only shows title and the several lines of the main text, but not showing information like your Blog "Alison Hill Last updated on Jan 6, 2021 22 min read hugo, blogdown, netlify, rmarkdown". Besides, the distance between each blog is very close, not so nice. Do you have any idea where I can change layout? This is my github, https://github.com/QZ-R/mywebsite01 Thank you very much

QZ-R commented 3 years ago

about last comment, I solved it by making blog a widget page. Thanks for your generous sharing of you original file for your website and it is super helpful!

saswatagitr commented 3 years ago

Hello Alison, First of all thanks a lot for writing this post. It is extremely helpful and so lucidly written that even a beginner like me can follow. However, I am stuck with something fundamental :-( Every time I try to deploy the site using netlify, it says 'public' folder does not exist. And I realized that the 'public' folder was never created even after I ran the command serve_site() or new_site() [I tried both in different attempts]. My blogdown version is 1.3 and my hugo version is 0.83.1. Moreover, when I am trying to commit (at the stage where it was suggested to), I find many folders which can't be checked and hence can't be committed (there is double ? sign next to them). I don't know what I am missing here. Why the most crucial folder did not get generated? And why I am unable to check those folders. As a result I failed every time I tried to deploy the website :( Your help is much appreciated. Stay safe. Best,

saswatagitr commented 3 years ago

Hi, I did the following:

  1. I opened the "shell" and ran this command: add git -A
  2. While deploying site from netlify, I ensured 'build command' was 'hugo' [it was: hugo --gc --minify -b $URL .. I dont know if they mean the same thing].
  3. next i opened 'show advanced' and selected 'new variable'. There for 'key' I wrote HUGO_VERSION and for 'value' I wrote the current version number of Hugo (which in my case is 0.83.1). I realized the netlify version of hugo and mine were not the same. Now I was able to deploy the site from netlify. I still don't know what did not work in my previous attempts and what did work this time (Still there is public folder by the way). But is this how we should commit every time we open a new site through a new repo? Many thanks Best,
javierfs commented 3 years ago

Thanks Allison for the tutorial! I must say I find a bit confusing the automatically creation of the files on the parent folder and the themes/starter-hugo-academic.

anyways, I was running this command: rstudioapi::navigateToFile("config/_default/params.toml") but it gives me the following error: Error in (function (filePath, line = 1L, col = 1L) : config/_default/params.toml does not exist.

I checked if is within the starter-hugo-academic/config/_default/ but is not there either. Could you clarify it? It also seems from your git repo that there is not config/_default/ neither in your parent folder nor in your theme folder

Many thanks!

shilaan commented 3 years ago

@javierfs try rstudioapi::navigateToFile("config/_default/params.yaml") instead. You might be on a newer version, in which these files are now .yaml format instead of .toml. :)

If you have similar issues, instead of using rstudioapi to navigate to files, you can always just check out the names/locations of files manually by, for example, going to your root folder > config > _default and seeing what's in it.

shilaan commented 3 years ago

P.S.: the reason you're not seeing these files in Alison's git repo is because she's no longer using wowchemy; she switched over to the apero theme.

trang-n commented 3 years ago

Hi Alison, I couldn't find the solution anywhere so decided to ask it here: My blogdown website is marked "not secure" and I don't know how to make it "secure" (change from http -> https) other than paying for a SSL certificate. I would appreciate any help! thanks!

shilaan commented 3 years ago

@trang-n try adding the following to your netlify.toml file:

[[redirects]]
  from = "http://trang.rbind.io/*"
  to = "https://trang.rbind.io/:splat"
  status = 301
  force = true
apreshill commented 3 years ago

@trang-n Are you using Netlify? Sometimes it can take some hours or even a day for the https to work, see: https://docs.netlify.com/domains-https/https-ssl/#netlify-managed-certificates

I use a redirects file in my static/ folder, but @shilaan's solution does the exact same thing: https://github.com/rbind/apreshill/blob/c62889bece33d8d7eaa4054921a53a81bf0fd26a/static/_redirects#L3

trang-n commented 3 years ago

@shilaan @apreshill Thank you for the suggestions! I fixed it by renewing the certificate on Netlify!

AntoineSoetewey commented 3 years ago

Hello,

Sorry if I missed the information somewhere in your post, but what is the advantage of having a domain name .rbind.io instead of .netlify.com?

Thanks, Antoine