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

Not working in RStudio Server #124

Closed
nwstephens opened this Issue Jun 19, 2017 · 20 comments

Comments

Projects
None yet
5 participants
@nwstephens
Copy link

nwstephens commented Jun 19, 2017

Blogdown for R Views not working in RStudio Server Pro.

@yihui

This comment has been minimized.

Copy link
Member

yihui commented Jun 19, 2017

It works only if you set relativeurls = true in config.toml.

@nstrayer

This comment has been minimized.

Copy link

nstrayer commented Aug 30, 2017

What's the protocol for dealing with static files in this context? When running rstudio server on port 8787 when rstudio spins up a server instead of putting out on a different port it appends it to the url ...:8787/p/<port num> which is breaking links to all static files. ( I have relativeurls = true set). Let me know if you need a more concrete code example.

@yihui

This comment has been minimized.

Copy link
Member

yihui commented Aug 30, 2017

@nstrayer You are right that the proxy mechanism /p/<port num>/ introduced the problem.

Setting relativeurls = true does not always work, because it is up to the theme author whether the theme really supports relative URLs consistently throughout the theme, which means the author must use the Hugo function relURL for all URLs and the variable .URL instead of .Permalink. Unfortunately, from what I can see, many theme authors didn't notice the importance of this, so your website may still contain absolute URLs, which fail to work with RStudio Server. As an example, you can take a look at the hugo-xmin theme that I wrote to see how relURL and .URL work:

@nstrayer

This comment has been minimized.

Copy link

nstrayer commented Aug 30, 2017

How would this work when implementing the file path in a post? For instance I want to include an image via the standard ![](/images/myImage.png) syntax. Is there an option in the theme settings for converting those using the relURL function?

The example i'm referring to, on my rstudio server instance I'm running with blogdown::serve_site() and the blog logo (generated by the following partial)

<header class="brand">
  <h1>
    <a href="{{.Site.BaseURL | relURL}}">
      <span id = "blog_logo">
         <img src="{{ .Site.Params.logo.url | relURL }}" alt="Blog Logo" style="height: 40px; width:40px">
      </span>
      {{if .IsHome}}
        {{if .Site.Params.showtitle}}
          <span id = "blog_title">
            {{.Site.Title}}
          </span>
        {{end}}
      {{end}}
    </a>
  </h1>
</header>

works great, but the images included in a post generated by this markdown

## Image test
![](/images/bite_laptop.png)
@nstrayer

This comment has been minimized.

Copy link

nstrayer commented Aug 30, 2017

screenshot 2017-08-30 at 3 55 50 pm
Interestingly the url does appear to be pointing where i'd expect. This points to ...8787/p/<portnum>/images/bite_laptop.png.

@yihui

This comment has been minimized.

Copy link
Member

yihui commented Aug 30, 2017

When relativeurls = true, Hugo does generate relative URLs in the body of a post. The main problem comes from the theme. Hugo won't convert URLs from the theme (e.g. those URLs for CSS in <head>).

@nstrayer

This comment has been minimized.

Copy link

nstrayer commented Aug 30, 2017

I see. I just got everything to work a-ok when I explicitly added canonifyURLs = false to the config.toml. I must have had an older version of hugo installed.

Thanks a ton for your help, I will be going through tuftesque to make sure I properly implemented relURL everywhere now!

@gauravsatav

This comment has been minimized.

Copy link

gauravsatav commented Nov 28, 2017

Hi guys, I see that this issue is still open here but just wanted to perform a quick check to know if any solution/workaround been found for this issue yet. I am trying to create a simple blog (with the default lithium theme) but as mentioned in the post above, the links for the website are not forming properly. I had then manually added the relativeurls = true option to the config.toml file and am still facing the issues of broken links. Also wanted to check if this issue is begin faced by everyone using RStudio Server.
Thanks again

@nstrayer

This comment has been minimized.

Copy link

nstrayer commented Nov 28, 2017

I managed to get everything working on rstudio server by adding url({{<originalURL> | relURL}}) to pretty much any url I could find in addition to adding relativeurls = true in the config.toml. I had to change a bunch of stuff in my own custom theme too so perhaps you are using a theme that doesn't have these implemented?

@gauravsatav

This comment has been minimized.

Copy link

gauravsatav commented Nov 28, 2017

Hi Nick, thanks for the reply. As I had previously mentioned I am using the default lithium theme. I would just like to understand when you say you've added the url({{<originalURL> | relURL}}) option to all the urls, to which files have you added these changes to? Is it only in the config.toml file?

This is how my config file looks:

relativeurls=true
languageCode = "en-us"
title = "A Hugo website"
theme = "hugo-lithium-theme"
googleAnalytics = ""
disqusShortname = ""
ignoreFiles = ["\\.Rmd$", "\\.Rmarkdown$", "_files$", "_cache$"]

[permalinks]
    post = "/:year/:month/:day/:slug/"

[[menu.main]]
    name = "About"
    url = "/about/"
[[menu.main]]
    name = "GitHub"
    url = "https://github.com/rstudio/blogdown"
[[menu.main]]
    name = "Twitter"
    url = "https://twitter.com/rstudio"

[params]
    description = "A website built through Hugo and blogdown."

    # options for highlight.js (version, additional languages, and theme)
    highlightjsVersion = "9.11.0"
    highlightjsCDN = "//cdn.bootcss.com"
    highlightjsLang = ["r", "yaml"]
    highlightjsTheme = "github"

    MathJaxCDN = "//cdn.bootcss.com"
    MathJaxVersion = "2.7.1"

    [params.logo]
    url = "logo.png"
    width = 50
    height = 50
    alt = "Logo"

@yihui

This comment has been minimized.

Copy link
Member

yihui commented Nov 28, 2017

@gauravsatav If you are using the default theme, all you need to do is set relativeurls = true in config.toml.

@gauravsatav

This comment has been minimized.

Copy link

gauravsatav commented Nov 28, 2017

@yihui as a result of setting the relativeurls=true parameter I am able to see the main index page within the public directory /public/index.html page properly however the links to all the rest of the files is still proving to be an issue. For example the link for About page is directed only to the /public/about/ directory rather than to the file /public/about/index.html

@nstrayer

This comment has been minimized.

Copy link

nstrayer commented Nov 28, 2017

@gauravsatav Oops, sorry I missed the part about you using the lithium theme. When I say I changed those URLs I mean that I changed them in all the files in my layouts/ folder.

@yihui

This comment has been minimized.

Copy link
Member

yihui commented Nov 28, 2017

@gauravsatav Are you using the Serve Site addin? You should always use it.

@gauravsatav

This comment has been minimized.

Copy link

gauravsatav commented Nov 28, 2017

Server Site addin ? I'm sorry I don't know what that is. I was simply following the instruction for creating a new blog directly using the new_site() command. Could you shed some light on the addin ?

@nstrayer my /layouts folder seems to be empty

I just now used the serve_site() command and the rebuild my site using build_site(). Still not able to link up those pages.

@yihui

This comment has been minimized.

Copy link
Member

yihui commented Nov 28, 2017

@gauravsatav I understand that you may be busy, but you need to read at least the Chapter 1 of the blogdown book: https://bookdown.org/yihui/blogdown/ Since you are using the RStudio IDE, there is no need to call any functions in blogdown explicitly. For example, if you want to create a new project, you can do so simply by clicking the menu (see Section 1.3 in the book). Then use the Serve Site addin.

@gauravsatav

This comment has been minimized.

Copy link

gauravsatav commented Nov 28, 2017

I am really sorry for asking that, actually I had read the book but I failed to recollect it. But I must admit that after reading the article (along with the rest of the book) It seems that the purpose of serve_site() is to reload the site to reflect the recent change made in the code. I too was doing the same thing (although manually) by using build_site(). I am still unable to resolve the issue
Any ways I really really appreciated your time on this.
Thanks again

@yihui

This comment has been minimized.

Copy link
Member

yihui commented Nov 28, 2017

  1. Restart your R session.
  2. Set relativeurls = true in config.toml.
  3. Serve Site.

Unless you really understand what build_site() does, please do not use it. If you follow the recommended workflow, you never need build_site(): https://bookdown.org/yihui/blogdown/workflow.html

@lponnala

This comment has been minimized.

Copy link

lponnala commented Jan 2, 2018

I can confirm that Yihui's solution works perfectly. I am using blogdown with the xmin theme on rstudio-server. All I had to do was set relativeurls = true in config.toml. And the preview showed up just fine!

@yihui

This comment has been minimized.

Copy link
Member

yihui commented Jan 21, 2019

I have set relativeURLs = true automatically when a site is being previewed in RStudio Server. As I said above (#124 (comment)), it really depends on the theme author whether this method works or not.

Cc @apreshill

@yihui yihui closed this in 81daf8e Jan 21, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment