open-neuroscience / open-neuroscience.github.io

new implementation of Open Neuroscience website
https://open-neuroscience.com/
MIT License
16 stars 5 forks source link

Improve autopost.R #19

Closed matiasandina closed 4 years ago

matiasandina commented 4 years ago

Here we can put a list of things that would be nice to add/check in the autopost script

Maybe we can do a strategy saving a txt file with the last datetime it ran and filtering the

amchagas commented 4 years ago

Couple of updates after using it for a little while:

matiasandina commented 4 years ago

The second issue might be more straight-forward to solve if we know the characters that are not allowed. The general idea would be:

not_allowed <- c(":", "/", ...)
sapply(not_allowed, function(tt) str_replace(string=title, pattern="tt", replacement=" "))

We can discuss whether it makes sense to replace with space or what.

If it's really a matter of using quotes and we want to use quotes, the idea would be to use shQuote(title) like this:

shQuote("a night at the opera")
[1] "'a night at the opera'"

This is done for the authors so it might be the way to go for the title too...My only concern is what the special characters do to the urls

amchagas commented 4 years ago

I think maybe just adding quotes is better as it allows people (as far as I understand) to name their project whatever they want and doesn't change the way it looks on the website. the example I mentioned was this one https://open-neuroscience.com/en/post/an_open-source_anthropomorphic_robot_hand_system_hri_hand/ there one can see the quotes do not appear on the rendering, so we are good...

matiasandina commented 4 years ago

Can you try it now using latest commit https://github.com/open-neuroscience/open-neuroscience-website/commit/40a07263fa6c34aa580cda94adc68e09371f8a1e

amchagas commented 4 years ago

this works for the post. just keeps the : on the folder name

matiasandina commented 4 years ago

That's because the folder name gets created by other piece of code here. I was just concerned by spaces at the time.

  # remove all spaces in title
  title <- gsub(x = title , pattern = " ", replacement = "_")
  # make folder on posts if it doesn't exist
  root = "content/en/post"
  if(title %in% list.files(root) == FALSE){
    # make dir
    dir.create(file.path(root, title))
  }

We can switch the first line to

title <- str_replace_all(title, pattern="[[:punct:]]", replacement="_")

That will kill all punctuation

amchagas commented 4 years ago

sounds good!

matiasandina commented 4 years ago

Done here https://github.com/open-neuroscience/open-neuroscience-website/commit/d9b2354f5a61c7a1b4ff2c54fa59f962cb90c3ae Closing this one because it got long. Let's open a new one if more improvements are needed.