diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index be70795..678e870 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -8,7 +8,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: misspell - uses: reviewdog/action-misspell@v1.10 + uses: reviewdog/action-misspell@v1.23 with: github_token: ${{ secrets.github_token }} locale: "US" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2b14f6d..2515c8e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,6 +3,8 @@ on: push: tags: - v* + branches: + - master jobs: build: @@ -10,31 +12,35 @@ jobs: steps: - id: get-version uses: battila7/get-version-action@v2 + - uses: actions/checkout@v2 - name: Install Ruby - uses: actions/setup-ruby@v1 + uses: ruby/setup-ruby@v1 with: #TODO: bring this back to 2.7 ruby-version: '2.6' - - uses: actions/checkout@v2 - - uses: actions/cache@v2.1.7 - with: - path: vendor/bundle - key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} - restore-keys: | - ${{ runner.os }}-gems- - - name: Install Gems + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Install pngout run: | - gem install bundler - bundle config path vendor/bundle - bundle install --jobs 4 --retry 3 + sudo apt-get update + sudo apt-get install -y wget + wget https://www.jonof.id.au/files/kenutils/pngout-20200115-linux.tar.gz + tar -xvf pngout-20200115-linux.tar.gz + sudo mv pngout-20200115-linux/amd64/pngout /usr/local/bin/ + rm -rf pngout-20200115-linux* - name: Build the static site run: bundle exec middleman build --bail - - name: Push the static site to prod + - name: Push the static site to stage env: - AWS_ACCESS_KEY_ID: ${{ secrets.CI_PROD_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_PROD_AWS_SECRET_ACCESS_KEY }} - PROD_S3_BUCKET: ${{ secrets.PROD_S3_BUCKET }} - run: aws s3 sync build $PROD_S3_BUCKET/build/ + AWS_ACCESS_KEY_ID: ${{ secrets.CI_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_AWS_SECRET_ACCESS_KEY }} + S3_BUCKET: ${{ secrets.STAGE_S3_BUCKET }} + run: aws s3 sync build $S3_BUCKET/build/ + # - name: Push the static site to prod + # env: + # AWS_ACCESS_KEY_ID: ${{ secrets.CI_PROD_AWS_ACCESS_KEY_ID }} + # AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_PROD_AWS_SECRET_ACCESS_KEY }} + # S3_BUCKET: ${{ secrets.PROD_S3_BUCKET }} + # run: aws s3 sync build $S3_BUCKET/build/ - name: Post Discord notification if: startsWith(github.ref, 'refs/tags/v') diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 18add35..3dde22b 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -20,23 +20,13 @@ jobs: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 - name: Install Ruby - uses: actions/setup-ruby@v1 + uses: ruby/setup-ruby@v1 with: #TODO: bring this back to 2.7 ruby-version: '2.6' - - uses: actions/checkout@v2 - - uses: actions/cache@v2.1.7 - with: - path: vendor/bundle - key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} - restore-keys: | - ${{ runner.os }}-gems- - - name: Install Gems - run: | - gem install bundler - bundle config path vendor/bundle - bundle install --jobs 4 --retry 3 + bundler-cache: true # runs 'bundle install' and caches installed gems automatically - run: echo $ENV - name: Attempt to build the static site run: bundle exec middleman build --bail diff --git a/config.rb b/config.rb index 8bb5fe1..dbd77b4 100644 --- a/config.rb +++ b/config.rb @@ -19,17 +19,31 @@ # With alternative layout # page "/path/to/file.html", layout: :otherlayout +# Ignore `photo.html.erb` to prevent it from being processed directly +ignore "photo.html" +ignore "photo.html.erb" + # create a photo landing page for every image ready do - #TODO: is there a better way to find all images? - images = sitemap.resources.map(&:path) - images = images.select {|s| s =~ /\.(jpg|png)$/i && s !~ /assets\// && s !~ /ogp-image/ } - images = images.map {|i| sitemap.find_resource_by_path(i)} - images.each do |img| - #TODO: add something like this to speed it up? - # next if sitemap.find_resource_by_path(...) - short_path = img.destination_path.sub(/#{File.extname(img.destination_path)}$/, '') - proxy short_path, "/photo.html", layout: 'layout', locals: { photo: img }, ignore: true + # Iterate over all .html.md.erb files to find associated images + sitemap.resources.select { |r| r.path.end_with?(".html") && !r.path.include?("photo.html") }.each do |page| + # Get the directory for the page + page_dir = File.dirname(page.path) + + # Find all image files in this directory + Dir.glob("source/#{page_dir}/*.{jpg,png}").each do |image_path| + # Remove "source/" prefix for the relative image path + relative_path = image_path.sub(%r{^source/}, '') + + # Get the destination path without the extension + short_path = relative_path.sub(/#{File.extname(relative_path)}$/, '') + + # Avoid duplicate proxies + next if sitemap.find_resource_by_path(short_path) + + # Create a proxy for the image + proxy short_path, "/photo.html", layout: 'layout', locals: { photo: sitemap.find_resource_by_path(relative_path) }, ignore: true + end end end