Cannot deploy website made by Blogdown in Github Pages - r

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/'

Related

R blogdown::serve_site() doesn't generate "public" folder when using Hugo "gesquive/slate" theme

I am trying to create a new blogdown project, and I've been using Yihui Xie's wonderful documentation to get started.
This works as expected:
Wen I run the below code, I see a live representation of the demo page, and the public folder is generated in my local directory.
library(blogdown)
blogdown::new_site(theme = "gcushen/hugo-academic")
blogdown::build_site()
blogdown::serve_site()
This does not work as expected:
But when I re-run using the "gesquive/slate" theme, I see a live representation of the demo page as expected, but no public folder is generated in my local directory. Without a public folder, I have nothing to send to Netlify.
library(blogdown)
blogdown::new_site(theme = "gesquive/slate")
blogdown::build_site()
blogdown::serve_site()
Why is a public folder generated when I use any Hugo theme other than "gesquive/slate"?
I expect that I'm misunderstanding something about how the package works with Hugo.
Look at the theme config.toml, the published folder (publishDir) is "docs", you can rename it to "public" if you wish.

github pages not building when uploading a website

Step 1: I create a new repository on my github and save the link:
Step 2: I create a new project
File -> Create Project -> Version Control -> Git
Fill in the details:
Repository URL: Taken from the new repository on my github
Project directory name: USER.github.io
Create project as subdirectory of: ~
Step 3: I create the blogdown website on my RStudio desktop
install.packages("blogdown")
blogdown::new_site(theme = "gcushen/hugo-academic")
Step 4: I use blogdown::build_site() to build the site where I can access it here http://127.0.0.1:4321/. I also run blogdown::serve_site().
Step 5: I now want to upload these files to my github
So in RStudio I select git -> Shell. I run the following:
git add -A
git commit -m "commit operation"
git push --force
Now I have all my files uploaded to github. I can make the modifications to the R markdown files in my RStudio and push them to github.
Based on the steps I have stated, where am I going wrong?
I go to my github repository and click settings, scroll down to github pages and see:
Your site is having problems building: Unable to build page. Please
try again later.
EDIT:
I added a URL to the github pages section in settings
Source Your GitHub Pages site is currently being built from the master
branch.
So that works, but when I go to my website link or github page USER.github.io I get a 404 Site not found message.
EDIT: I think it is something to do witht he public folder and that I should only push to github this public folder or set the website to only read this public folder.
On github it stats User pages must be built from the master branch. - which I think the master branch is unreadable.
https://sourcethemes.com/academic/docs/deployment/
I uploaded my website simply by copying the home directory and drop it in the netlify. However, I edited the .toml file as explained here to include on top of it the following 2 parameters:
relativeurls = true
canonifyurls = false
It is now working perfectly.

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.

Local preview of draft posts does not work

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.

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