From 3e47aac5307ed828b52d3547dad53b5c304107ca Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Mon, 16 Apr 2018 08:45:12 +0200 Subject: [PATCH] fix links for tag builds (#1) --- examples/example.jl | 2 +- src/Examples.jl | 31 +++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/examples/example.jl b/examples/example.jl index b4ecdcf..5586b24 100644 --- a/examples/example.jl +++ b/examples/example.jl @@ -4,7 +4,7 @@ #' The source file can be found [here](@__REPO_ROOT_URL__examples/example.jl). #' The generated markdown can be found here: [`example.md`](./example.md), the #' generated notebook can be found here: -#' [`example.ipynb`](@__NBVIEWER__ROOT_URL__generated/example.ipynb), and the +#' [`example.ipynb`](@__NBVIEWER_ROOT_URL__generated/example.ipynb), and the #' plain script output can be found here: [`example.jl`](./example.jl). #' ### Rational numbers in Julia diff --git a/src/Examples.jl b/src/Examples.jl index cf2483d..371fede 100644 --- a/src/Examples.jl +++ b/src/Examples.jl @@ -461,16 +461,27 @@ function execute_notebook(nb) nb end -function fixlinks(content; commit = "master") - # replace @__REPO__ to master/commit - repo = get(ENV, "TRAVIS_REPO_SLUG", "") - root_url = "https://github.com/$(repo)/blob/$(commit)/" - content = replace(content, "@__REPO_ROOT_URL__" => root_url) - # replace @__NBVIEWER__ to latest or version directory - folder = "latest" - branch = "gh-pages" - nbviewer_root_url = "https://nbviewer.jupyter.org/github/$(repo)/blob/$(branch)/$(folder)/" - content = replace(content, "@__NBVIEWER__ROOT_URL__" => nbviewer_root_url) +function fixlinks(content; branch = "gh-pages", commit = "master") + if get(ENV, "HAS_JOSH_K_SEAL_OF_APPROVAL", "") == "true" + travis_repo_slug = get(ENV, "TRAVIS_REPO_SLUG", "") + # use same logic as Documenter to figure out the deploy folder + travis_tag = get(ENV, "TRAVIS_TAG", "") + if isempty(travis_tag) + folder = "latest" + else + # use the versioned directory for links, even for the stable and release- + # folders since this will never change + folder = travis_tag + end + # replace @__REPO_ROOT_URL__ to master/commit + repo_root_url = "https://github.com/$(travis_repo_slug)/blob/$(commit)/" + content = replace(content, "@__REPO_ROOT_URL__" => repo_root_url) + # replace @__NBVIEWER_ROOT_URL__ to latest or version directory + nbviewer_root_url = "https://nbviewer.jupyter.org/github/$(travis_repo_slug)/blob/$(branch)/$(folder)/" + content = replace(content, "@__NBVIEWER_ROOT_URL__" => nbviewer_root_url) + else + @info "not running on Travis, skipping link-fix." + end return content end