From 4996c8caf35052cc3cd4f53dcafe59b5f11c5d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Bobot?= Date: Thu, 7 Nov 2019 13:14:25 +0100 Subject: [PATCH 1/4] Rewrite link to download to link to gitlab --- .gitlab-ci.yml | 2 ++ rewrite_url_download.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 rewrite_url_download.rb diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2e70e5ab..e8423f9a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,6 +23,7 @@ test: #- ./generate ../assets/Changelog -o ../html/changelog.html - cd .. - bundle exec jekyll build -d test + - cd test; ruby ../rewrite_url_download.rb artifacts: paths: - test @@ -39,6 +40,7 @@ pages: #- ./generate ../assets/Changelog -o ../html/changelog.html - cd .. - bundle exec jekyll build -d public + - cd public; ruby ../rewrite_url_download.rb artifacts: paths: - public diff --git a/rewrite_url_download.rb b/rewrite_url_download.rb new file mode 100644 index 00000000..8745d444 --- /dev/null +++ b/rewrite_url_download.rb @@ -0,0 +1,12 @@ +require 'cgi' +require 'rubygems' rescue nil +require 'nokogiri' + +Dir.glob('**/*.html') do |file_path| + doc = Nokogiri::HTML(open(file_path)) + doc.css("a").each do |link| + next if link.attributes["href"].nil? or not link.attributes["href"].value.start_with?("/download/") + link.attributes["href"].value = "https://git.frama-c.com/frama-c/frama-c.frama-c.com/raw/master" + link.attributes["href"].value + end + doc.write_to(open(file_path, 'w')) +end -- GitLab From a0d0b9c95314b5be35d471f46fbd6fd7d6132e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Bobot?= Date: Thu, 7 Nov 2019 13:21:35 +0100 Subject: [PATCH 2/4] Add nokogiri dependency --- Gemfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Gemfile b/Gemfile index 83bc3bdb..47521ed3 100644 --- a/Gemfile +++ b/Gemfile @@ -30,3 +30,6 @@ gem "wdm", "~> 0.1.1", :install_if => Gem.win_platform? gem 'jekyll-paginate', group: :jekyll_plugins gem 'jekyll-category-pages', group: :jekyll_plugins + +#For rewriting link after generation +gem 'nokogiri' -- GitLab From 0d55e0854f66ae39e7bc097292360a53daeaf6c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Bobot?= Date: Thu, 7 Nov 2019 13:25:25 +0100 Subject: [PATCH 3/4] Don't forget to run in the bundle --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e8423f9a..2cd28fee 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,7 +23,7 @@ test: #- ./generate ../assets/Changelog -o ../html/changelog.html - cd .. - bundle exec jekyll build -d test - - cd test; ruby ../rewrite_url_download.rb + - cd test; bundle exec ruby ../rewrite_url_download.rb artifacts: paths: - test @@ -40,7 +40,7 @@ pages: #- ./generate ../assets/Changelog -o ../html/changelog.html - cd .. - bundle exec jekyll build -d public - - cd public; ruby ../rewrite_url_download.rb + - cd public; bundle exec ruby ../rewrite_url_download.rb artifacts: paths: - public -- GitLab From ba75594a4bd15efd429614d2f93cbf2176e9c40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Bobot?= Date: Thu, 7 Nov 2019 13:28:13 +0100 Subject: [PATCH 4/4] Use instead commandline argument --- .gitlab-ci.yml | 4 ++-- rewrite_url_download.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2cd28fee..c4274152 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,7 +23,7 @@ test: #- ./generate ../assets/Changelog -o ../html/changelog.html - cd .. - bundle exec jekyll build -d test - - cd test; bundle exec ruby ../rewrite_url_download.rb + - bundle exec ruby rewrite_url_download.rb test/ artifacts: paths: - test @@ -40,7 +40,7 @@ pages: #- ./generate ../assets/Changelog -o ../html/changelog.html - cd .. - bundle exec jekyll build -d public - - cd public; bundle exec ruby ../rewrite_url_download.rb + - bundle exec ruby rewrite_url_download.rb public/ artifacts: paths: - public diff --git a/rewrite_url_download.rb b/rewrite_url_download.rb index 8745d444..c3a9c76d 100644 --- a/rewrite_url_download.rb +++ b/rewrite_url_download.rb @@ -2,7 +2,7 @@ require 'cgi' require 'rubygems' rescue nil require 'nokogiri' -Dir.glob('**/*.html') do |file_path| +Dir.glob(ARGV[0] + '**/*.html') do |file_path| doc = Nokogiri::HTML(open(file_path)) doc.css("a").each do |link| next if link.attributes["href"].nil? or not link.attributes["href"].value.start_with?("/download/") -- GitLab