From 5b31f5dea03049e76013773769dd76be2c9bd8d4 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 00:24:30 -0300 Subject: [PATCH 1/7] Remove old framework files and replace with Docker --- Gemfile | 12 ---- Gemfile.lock | 138 ------------------------------------- README.md | 14 ++++ Rakefile | 11 --- build.sh | 5 ++ config.rb | 58 ---------------- deploy.sh | 16 +---- lib/multilang.rb | 16 ----- lib/nesting_unique_head.rb | 22 ------ lib/toc_data.rb | 31 --------- lib/unique_head.rb | 24 ------- 11 files changed, 20 insertions(+), 327 deletions(-) delete mode 100644 Gemfile delete mode 100644 Gemfile.lock delete mode 100644 Rakefile create mode 100644 build.sh delete mode 100644 config.rb delete mode 100644 lib/multilang.rb delete mode 100644 lib/nesting_unique_head.rb delete mode 100644 lib/toc_data.rb delete mode 100644 lib/unique_head.rb diff --git a/Gemfile b/Gemfile deleted file mode 100644 index ec5c419a..00000000 --- a/Gemfile +++ /dev/null @@ -1,12 +0,0 @@ -ruby '>=2.3.1' -source 'https://rubygems.org' - -# Middleman -gem 'middleman', '~>4.3' -gem 'middleman-syntax', '~> 3.2' -gem 'middleman-autoprefixer', '~> 2.7' -gem 'middleman-sprockets', '~> 4.1' -gem 'rouge', '~> 3.20' -gem 'redcarpet', '~> 3.5.1' -gem 'nokogiri', '~> 1.11.0' -gem 'sass' diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index e9e8233b..00000000 --- a/Gemfile.lock +++ /dev/null @@ -1,138 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - activesupport (5.2.4.3) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - autoprefixer-rails (9.5.1.1) - execjs - backports (3.18.1) - coffee-script (2.4.1) - coffee-script-source - execjs - coffee-script-source (1.12.2) - concurrent-ruby (1.1.7) - contracts (0.13.0) - dotenv (2.7.6) - erubis (2.7.0) - execjs (2.7.0) - fast_blank (1.0.0) - fastimage (2.2.0) - ffi (1.13.1) - haml (5.1.2) - temple (>= 0.8.0) - tilt - hamster (3.0.0) - concurrent-ruby (~> 1.0) - hashie (3.6.0) - i18n (0.9.5) - concurrent-ruby (~> 1.0) - kramdown (2.3.0) - rexml - listen (3.0.8) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) - memoist (0.16.2) - middleman (4.3.8) - coffee-script (~> 2.2) - haml (>= 4.0.5) - kramdown (>= 2.3.0) - middleman-cli (= 4.3.8) - middleman-core (= 4.3.8) - middleman-autoprefixer (2.10.1) - autoprefixer-rails (~> 9.1) - middleman-core (>= 3.3.3) - middleman-cli (4.3.8) - thor (>= 0.17.0, < 2.0) - middleman-core (4.3.8) - activesupport (>= 4.2, < 6.0) - addressable (~> 2.3) - backports (~> 3.6) - bundler - contracts (~> 0.13.0) - dotenv - erubis - execjs (~> 2.0) - fast_blank - fastimage (~> 2.0) - hamster (~> 3.0) - hashie (~> 3.4) - i18n (~> 0.9.0) - listen (~> 3.0.0) - memoist (~> 0.14) - padrino-helpers (~> 0.13.0) - parallel - rack (>= 1.4.5, < 3) - sassc (~> 2.0) - servolux - tilt (~> 2.0.9) - uglifier (~> 3.0) - middleman-sprockets (4.1.1) - middleman-core (~> 4.0) - sprockets (>= 3.0) - middleman-syntax (3.2.0) - middleman-core (>= 3.2) - rouge (~> 3.2) - mini_portile2 (2.5.0) - minitest (5.14.1) - nokogiri (1.11.0) - mini_portile2 (~> 2.5.0) - racc (~> 1.4) - padrino-helpers (0.13.3.4) - i18n (~> 0.6, >= 0.6.7) - padrino-support (= 0.13.3.4) - tilt (>= 1.4.1, < 3) - padrino-support (0.13.3.4) - activesupport (>= 3.1) - parallel (1.19.2) - public_suffix (4.0.5) - racc (1.5.2) - rack (2.2.3) - rb-fsevent (0.10.4) - rb-inotify (0.10.1) - ffi (~> 1.0) - redcarpet (3.5.1) - rexml (3.2.4) - rouge (3.20.0) - sass (3.7.4) - sass-listen (~> 4.0.0) - sass-listen (4.0.0) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) - sassc (2.4.0) - ffi (~> 1.9) - servolux (0.13.0) - sprockets (3.7.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - temple (0.8.2) - thor (1.0.1) - thread_safe (0.3.6) - tilt (2.0.10) - tzinfo (1.2.7) - thread_safe (~> 0.1) - uglifier (3.2.0) - execjs (>= 0.3.0, < 3) - -PLATFORMS - ruby - -DEPENDENCIES - middleman (~> 4.3) - middleman-autoprefixer (~> 2.7) - middleman-sprockets (~> 4.1) - middleman-syntax (~> 3.2) - nokogiri (~> 1.11.0) - redcarpet (~> 3.5.1) - rouge (~> 3.20) - sass - -RUBY VERSION - ruby 2.3.3p222 - -BUNDLED WITH - 2.1.4 diff --git a/README.md b/README.md index 4a9611c3..27ca5e22 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,17 @@ Repository of documentation REST API WooCommerce. This project is based on [Slate](https://github.com/tripit/slate). + +## Usage ## + +To generate docs run: + +```bash +./build.sh +``` + +To deploy generated docs: + +```bash +./deploy.sh +``` diff --git a/Rakefile b/Rakefile deleted file mode 100644 index 8884b3ef..00000000 --- a/Rakefile +++ /dev/null @@ -1,11 +0,0 @@ -require 'middleman-gh-pages' -require 'rake/clean' - -CLOBBER.include('build') - -task :default => [:build] - -desc "Run a virtual environment" -task :server do - sh "bundle exec middleman server" -end diff --git a/build.sh b/build.sh new file mode 100644 index 00000000..48b336f0 --- /dev/null +++ b/build.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -o errexit #abort if any command fails + +rm -rf build +docker run --rm --name slate -v $(pwd)/build:/srv/slate/build -v $(pwd)/source:/srv/slate/source slatedocs/slate diff --git a/config.rb b/config.rb deleted file mode 100644 index 24887979..00000000 --- a/config.rb +++ /dev/null @@ -1,58 +0,0 @@ -# Unique header generation -require './lib/unique_head.rb' - -# Markdown -set :markdown_engine, :redcarpet -set :markdown, - fenced_code_blocks: true, - smartypants: true, - disable_indented_code_blocks: true, - prettify: true, - strikethrough: true, - tables: true, - with_toc_data: true, - no_intra_emphasis: true, - renderer: UniqueHeadCounter - -# Assets -set :css_dir, 'stylesheets' -set :js_dir, 'javascripts' -set :images_dir, 'images' -set :fonts_dir, 'fonts' - -# Activate the syntax highlighter -activate :syntax -ready do - require './lib/multilang.rb' -end - -activate :sprockets - -activate :autoprefixer do |config| - config.browsers = ['last 2 version', 'Firefox ESR'] - config.cascade = false - config.inline = true -end - -# Github pages require relative links -activate :relative_assets -set :relative_links, true - -# Build Configuration -configure :build do - # If you're having trouble with Middleman hanging, commenting - # out the following two lines has been known to help - activate :minify_css - activate :minify_javascript - # activate :relative_assets - # activate :asset_hash - # activate :gzip -end - -# Deploy Configuration -# If you want Middleman to listen on a different port, you can set that below -set :port, 4567 - -helpers do - require './lib/toc_data.rb' -end diff --git a/deploy.sh b/deploy.sh index f122ba7c..d7d264d8 100755 --- a/deploy.sh +++ b/deploy.sh @@ -15,15 +15,8 @@ Options: deploy branch. -n, --no-hash Don't append the source commit's hash to the deploy commit's message. - --source-only Only build but not push - --push-only Only push but not build " - -run_build() { - bundle exec middleman build --clean -} - parse_args() { # Set args from a local environment file. if [ -e ".env" ]; then @@ -205,11 +198,4 @@ sanitize() { "$@" 2> >(filter 1>&2) | filter } -if [[ $1 = --source-only ]]; then - run_build -elif [[ $1 = --push-only ]]; then - main "$@" -else - run_build - main "$@" -fi +main "$@" diff --git a/lib/multilang.rb b/lib/multilang.rb deleted file mode 100644 index 36fbe5b1..00000000 --- a/lib/multilang.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Multilang - def block_code(code, full_lang_name) - if full_lang_name - parts = full_lang_name.split('--') - rouge_lang_name = (parts) ? parts[0] : "" # just parts[0] here causes null ref exception when no language specified - super(code, rouge_lang_name).sub("highlight #{rouge_lang_name}") do |match| - match + " tab-" + full_lang_name - end - else - super(code, full_lang_name) - end - end -end - -require 'middleman-core/renderers/redcarpet' -Middleman::Renderers::MiddlemanRedcarpetHTML.send :include, Multilang diff --git a/lib/nesting_unique_head.rb b/lib/nesting_unique_head.rb deleted file mode 100644 index 01278371..00000000 --- a/lib/nesting_unique_head.rb +++ /dev/null @@ -1,22 +0,0 @@ -# Nested unique header generation -require 'middleman-core/renderers/redcarpet' - -class NestingUniqueHeadCounter < Middleman::Renderers::MiddlemanRedcarpetHTML - def initialize - super - @@headers_history = {} if !defined?(@@headers_history) - end - - def header(text, header_level) - friendly_text = text.gsub(/<[^>]*>/,"").parameterize - @@headers_history[header_level] = text.parameterize - - if header_level > 1 - for i in (header_level - 1).downto(1) - friendly_text.prepend("#{@@headers_history[i]}-") if @@headers_history.key?(i) - end - end - - return "#{text}" - end -end diff --git a/lib/toc_data.rb b/lib/toc_data.rb deleted file mode 100644 index 4a04efee..00000000 --- a/lib/toc_data.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'nokogiri' - -def toc_data(page_content) - html_doc = Nokogiri::HTML::DocumentFragment.parse(page_content) - - # get a flat list of headers - headers = [] - html_doc.css('h1, h2, h3').each do |header| - headers.push({ - id: header.attribute('id').to_s, - content: header.children, - title: header.children.to_s.gsub(/<[^>]*>/, ''), - level: header.name[1].to_i, - children: [] - }) - end - - [3,2].each do |header_level| - header_to_nest = nil - headers = headers.reject do |header| - if header[:level] == header_level - header_to_nest[:children].push header if header_to_nest - true - else - header_to_nest = header if header[:level] < header_level - false - end - end - end - headers -end diff --git a/lib/unique_head.rb b/lib/unique_head.rb deleted file mode 100644 index d42bab2a..00000000 --- a/lib/unique_head.rb +++ /dev/null @@ -1,24 +0,0 @@ -# Unique header generation -require 'middleman-core/renderers/redcarpet' -require 'digest' -class UniqueHeadCounter < Middleman::Renderers::MiddlemanRedcarpetHTML - def initialize - super - @head_count = {} - end - def header(text, header_level) - friendly_text = text.gsub(/<[^>]*>/,"").parameterize - if friendly_text.strip.length == 0 - # Looks like parameterize removed the whole thing! It removes many unicode - # characters like Chinese and Russian. To get a unique URL, let's just - # URI escape the whole header - friendly_text = Digest::SHA1.hexdigest(text)[0,10] - end - @head_count[friendly_text] ||= 0 - @head_count[friendly_text] += 1 - if @head_count[friendly_text] > 1 - friendly_text += "-#{@head_count[friendly_text]}" - end - return "#{text}" - end -end From 04b6047bbbdf02a301dd1e14a8f9780a840a4ea9 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 00:33:14 -0300 Subject: [PATCH 2/7] Fixed chmod --- build.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 build.sh diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 From 8ecaad39c5a1272bc66c831b703177105c40778a Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 01:33:23 -0300 Subject: [PATCH 3/7] Added deploy workflow --- .github/workflows/deploy.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..366921da --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,20 @@ +name: Deploy on push +on: push +jobs: + build-and-deploy: + if: github.repository_owner == 'woocommerce' + name: Build and deploy + runs-on: [ubuntu-latest] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Build + run: ./build.sh + - name: Deploy to GitHub Pages + if: success() + uses: crazy-max/ghaction-github-pages@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + target_branch: gh-pages + build_dir: build From eed04c5dc2d89f088445e116f4148c64a2654849 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 01:45:47 -0300 Subject: [PATCH 4/7] Deploy only when push to trunk --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 366921da..3da9ed64 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,7 +2,7 @@ name: Deploy on push on: push jobs: build-and-deploy: - if: github.repository_owner == 'woocommerce' + if: github.repository_owner == 'woocommerce' && github.ref == 'refs/heads/trunk' name: Build and deploy runs-on: [ubuntu-latest] steps: From 72628693f4153c56a45b9d31150ac95ef3201874 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 01:52:28 -0300 Subject: [PATCH 5/7] Improve how workflow triggers --- .github/workflows/deploy.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3da9ed64..c8d3f194 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,8 +1,11 @@ name: Deploy on push -on: push +on: + push: + branches: + - trunk jobs: build-and-deploy: - if: github.repository_owner == 'woocommerce' && github.ref == 'refs/heads/trunk' + if: github.repository_owner == 'woocommerce' name: Build and deploy runs-on: [ubuntu-latest] steps: From 4efb2e353b34ab328a817b8bfda7ba69688c24b1 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 19:33:54 -0300 Subject: [PATCH 6/7] Coding standards --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 48b336f0..cbc3c6f2 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -o errexit #abort if any command fails +set -o errexit # Abort if any command fails rm -rf build docker run --rm --name slate -v $(pwd)/build:/srv/slate/build -v $(pwd)/source:/srv/slate/source slatedocs/slate From cdb855adda1a3c56e68231451e7e9c833de897af Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 18 Mar 2021 22:07:25 -0300 Subject: [PATCH 7/7] Update deploy.yml --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c8d3f194..452aadc5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,7 +7,7 @@ jobs: build-and-deploy: if: github.repository_owner == 'woocommerce' name: Build and deploy - runs-on: [ubuntu-latest] + runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2