Local preview of draft posts does not work - r

I tried to reproduce (and understand) Appendix C.3 Building a website for local preview of the blogdown book:
I have demonized the server successfully in my ~/.Rprofile with
options(servr.daemon = TRUE)
Whenever I run blogdown::serve_site() those markdown files (.md) which are marked with draft: yes in their yaml-header do not appear at http://127.0.0.1:4321/ (or whatever the address of the local server is). If I change to draft: no they do appear. But in my understanding, all files should appear on the local website.
If i build the site with the menu 'Build Website' via GitHub and Netlify the draft: yes posts do not appear (= correct behavior)
If I use hugo -D from the terminal, everything works as expected; `draft: yes' file do appear! But this works (as anticipated) only with .md files (not with .Rmd files).
At the moment I have to change the draft status every time I want to inspect the file locally with the danger that I forget to set it back to draft: yes and publish those files inadvertently on my live site.
So how can I see and edit draft: yes files on the local server?

With blogdown 0.1 and your example at https://github.com/petzi53/test-academic-theme, I had to remove the comment after baseurl in config.toml, i.e., change
baseurl = "/" # End your URL with a `/` trailing slash.
to
baseurl = "/"
Then I ran blogdown::serve_site(), and I can see the draft post:
The issue with comments has been fixed in the development version of blogdown on Github.

Related

Cannot deploy website made by Blogdown in Github Pages

I want to deploy a Hugo-based website made using the blogdown package in Github Pages, while keeping the R source code of the website in the same repository. This should be achievable by generating the website files in the docs directory in the Github repository, and then pointing Github Pages to the docs folder in the main branch. However, I could not make it work.
Here, I describe a simple blogdown site to demonstrate the problem. The directory is created using Rstudio with the options as shown in the following picture.
I have edited the config.toml file, in particular to set the publishDir as docs and add a logo to the website. The content of the edited config.toml file is given below.
baseurl = "/"
publishDir = "docs"
languageCode = "en-us"
title = "Blogdown website in Github Pages"
theme = "hugo-lithium"
googleAnalytics = ""
disqusShortname = ""
ignoreFiles = ["\\.Rmd$", "\\.Rmarkdown$", "_files$", "_cache$"]
[permalinks]
post = "/:year/:month/:day/:slug/"
[[menu.main]]
name = "About"
url = "/about/"
[params]
description = "Demonstrating problem in deploying a blogdown website in Github Pages."
# options for highlight.js (version, additional languages, and theme)
highlightjsVersion = "9.12.0"
highlightjsCDN = "//cdnjs.cloudflare.com/ajax/libs"
highlightjsLang = ["r", "yaml"]
highlightjsTheme = "github"
MathJaxCDN = "//cdnjs.cloudflare.com/ajax/libs"
MathJaxVersion = "2.7.5"
[params.logo]
url = "logo.png"
width = 50
height = 50
alt = "Logo"
I have also edited the value of the publish parameter in the netlify.toml file to docs. I have done this to have the option to deploy the website using Netlify apart from Github Pages. The content of the edited netlify.toml file is:
[build]
command = 'hugo'
publish = 'docs'
[build.environment]
HUGO_VERSION = '0.89.4'
[context]
[context.branch-deploy]
command = 'hugo -F -b $DEPLOY_PRIME_URL'
[context.deploy-preview]
command = 'hugo -F -b $DEPLOY_PRIME_URL'
[context.production]
[context.production.environment]
HUGO_ENV = 'production'
Content of the website is added in the content folder, which includes an about.md file and a sample post 2021-12-09-sample-post.Rmd. The structure of the content folder is:
content
|-- about.md
|-- post
|-- 2021-12-09-sample-post.Rmd
The logo is added by placing the file logo.png in the static\images directory. The source code of this example can be downloaded from here. The local build in RStudio runs perfectly well. The files after building the website locally are uploaded here. I have placed the .nojekyll file in both the main directory and the docs folder to prevent Github Pages from using Jekyll.
However, the generated Github Pages site does not work. But it works perfectly in Netlify.
I have also tried changing the value of the baseurl argument in the file config.toml to point to the Github hosting directory. The website is generated perfectly in RStudio through blogdown. The source code as well as the generated website files are uploaded here. But now, neither Github Pages nor Netlify correctly deploys the website.
I wish to be able to deploy the website in both Github Pages and Netlify, just like which can be done for a website generated using the bookdown package in R. If that is not possible at all, I wish to be able to deploy the website in Github Pages at least. I wonder what mistakes I am making in the website code or configuration.
Short answer: set relativeURLs = true in config.toml, so that your pages use relative URLs (but this is really up to the theme's support for relative URLs; the hugo-lithium theme should be good).
Longer answer:
Your Github Pages URL https://joydeepchowdhury.github.io/deploymentproblem/ contains a subpath deploymentproblem/, whereas your Netlify URL does not: https://deploymentproblem.netlify.app/. If you don't use relative URLs, resources won't be correctly loaded on one of these two sites, e.g., /images/logo.png on https://joydeepchowdhury.github.io/deploymentproblem/ means https://joydeepchowdhury.github.io/images/logo.png, which is wrong (should have been https://joydeepchowdhury.github.io/deploymentproblem/images/logo.png instead), but it is correct on the Netlify site: https://deploymentproblem.netlify.app/images/logo.png. Absolute/relative URLs are tricky but extremely important to understand. You may read the last part of the Appendix B.1 of the blogdown book.
Another solution is to specify different baseURLs for different sites. For example, you may configure
baseURL: "https://joydeepchowdhury.github.io/deploymentproblem/"
in config.toml, but override it in netlify.toml:
[build]
command = 'hugo -b https://deploymentproblem.netlify.app/'

Issue with serve_site() r blogdown

I'm using blogdown and Hugo to generate a website.
I've created a new R project and have downloaded the theme using:
blogdown::new_site(dir = "Theme", theme = 'pacollins/hugo-future-imperfect-slim') and I can preview the template once downloaded. However, if I close R and then restart and I use the add-in "serve site" I get the following error message:
Error in site_root(config) :
Could not find config.toml / config.yaml under...
and then the directory that the config.toml file is saved in (and all of the rest of the theme files) are listed.
I can't understand what's changing between being able to preview the site in R Studio Viewer, then quitting R and restarting and it not being able to find the config file.
I did find this advice: https://github.com/rstudio/blogdown/issues/48 which suggests that my working directory is not the root directory of the website. There are two things I don't understand:
1) How can the the root directory and working directory work together okay when I initially download the theme, until I quit R and restart, and then they appear to not be the same?
2) How to I change the root directory of the website to fix the issue?
Thanks!
If you followed the blogdown's documentation to create a new site with the command "blogdown::new_site(dir="/your/website/dir")", it will set your working directory to "/your/website/dir".
When you restart R/Rstudio, your current working directory is reset (probably to your home directory). You can check the current working directory with getwd().
The solution is simply set up the working directory:
The simpler way is to execute setwd("/your/website/dir"), then you should be able to run blogdown::serve_site()
The recommended way is to create a Rstudio project at /your/website/dir with File-New Project-Existing Directory. It will create a .Rproj file under the root directory of your website. After that, you can "open project" and work on your website, then preview with serve_site().

Drafts rendered by netlify when draft: true in yaml

I am running at blogdown site from this github repo hosted by Netlify at https://timmastny.rbind.io/
In website2/content/blog/ I have two posts
2018-01-16-git-blogdown-project-workflow.Rmd
and
2018-01-13-bayesian-meta-analysis-powerlifting.Rmd
You can see that in the YAML of both posts, I have draft: true and in the second one I even have publishdate: '2018-01-20' which is in the future as of this post.
However, with these changes pushed to github and Netlify deployed with a clean cache, on my actual website I still see the posts:
https://timmastny.rbind.io/
What am I missing about draft: true?
I've read sections 2.3.1 and D.3 of the books, but I'm not sure. I've also updated Hugo to 0.32.4 and am on the latest version of blogdown.
Edit: I've deleted the public folder and added public to gitignore. Netlify had a 16 minute build which was published. But on the actual website I get a Page Not Found error.
Here's the log: https://app.netlify.com/sites/timmastny/deploys/5a60c299df99532a0147c3d7
Here's my deploy settings on Netlify. They should match the suggestions in 3.1 of the blogdown book:
Deploy settings
Repository: https://github.com/tmastny/website2
Build command: hugo
Publish directory: public
Production branch: master
Branch deploys: Deploy only the production branch and its deploy previews
Public deploy logs: Logs are public
Build environment variables:
HUGO_VERSION 0.32.4
I am going to assume you are using public as your deploy folder for Netlify.
Issue #1
Your public folder is in your repository, so it is checked out to the Netlify site and when you run your build your posts already exist in that folder, so they are always going to be deployed.
Solution #1
Delete the public folder from your project and add a .gitignore for the public folder.
The deploy should build the public folder fresh on each deploy, so it can compare the CDN with your build and copy the correct files only.
Issue #2 (updated question)
The Hugo theme is set to theme = "hugo-xmin" in the config.toml. When checking out the repository from GitHub, this theme folder is empty. It would be empty on Netlify as well, so the build becomes invalid.
Solution #2
Changed to a valid theme theme = "hugo-lithium-theme" in the config.toml and the build starts to create your site pages.
Original Issue
When updating draft: true in .Rmd does not ignore on build.
Solution (for Original)
Hugo is not processing your content for .Rmd, it is using your content from the processed .html files created. So you need to make sure you are committing the content for those files with draft: true in them to your repository before a build.

GitLab rendering the wrong README in Project & Public views

I'm using R markdown (README.Rmd) to knit/render to README.md at the top level of a project directory. GitLab (both in Project and Public views) chooses the .Rmd file to render vs the .md file and produces a visual mess instead of a nicely-formatted project description.
Is there any way to tell GitLab to ignore .Rmd files when picking the "right" one to use for the project/public view or am I left with a workflow that will mean keeping the README.Rmd in a separate directory then having the R project build process render and copy a knitted README.md to the top-level project directory?
This is a fresh install (this week) of a self-hosted instance of GitLab, but you can see it rendering the wrong README here.
I've reproduced this issue. I'll look into this tomorrow and make a PR for fixing this.

Django CMS - Template Does Not Exist Error while creating first page

I followed the instructions for installing Django CMS on my mac. When I run "manage.py cms check", everything is fine, except it says it cannot find the template_1.html. When I go into the admin to create a page, the template is in the Template drop down. When I try to save the page it gives me "TemplateDoesNotExist at /admin/cms/page/add/".
Maybe it's noteworthy, I was having issues with the url prior to this error. I was not able to open the admin or even get main page to render in the browser. After searching stack overflow I found the same issue. I changed the url patterns from the "urlpatterns = i18n_patterns" to the standard. That worked. Now I have this issue. Any assistance would be appreciated. Thanks.
Link to Traceback if needed:
http://dpaste.com/hold/1430437/
I had the same error (on Ubuntu 12.04)
Following the django-cms 2.4.3 installation instruction,
django-admin.py startproject myproject
creates a directory myproject (in which manage.py resides) and a subdirectory, also named myproject, which contains the setting files and the templates directory.
I don't know if this is the intention of the authors of the django-cms doc. But the instruction
os.path.join(PROJECT_PATH, "templates"),
in the TEMPLATE_DIRS setting points to /absolute/path/to/myproject/templates.
This should be changed to:
os.path.join(PROJECT_PATH, "myproject/templates"),
to point to the correct directory /absolute/path/to/myproject/myproject/templates

Resources