From 2d5668a9e016711be849ccae816a4bee7ff5614f Mon Sep 17 00:00:00 2001 From: Andrew Mason Date: Fri, 14 Jan 2022 17:49:31 -0700 Subject: [PATCH 1/3] feat: add bundled configuration for Vercel --- .../bridgetown-core/configurations/vercel.rb | 4 ++ .../configurations/vercel/vercel.json | 45 +++++++++++++++++++ .../configurations/vercel/vercel_url.rb | 10 +++++ .../src/_docs/bundled-configurations.md | 11 +++++ 4 files changed, 70 insertions(+) create mode 100644 bridgetown-core/lib/bridgetown-core/configurations/vercel.rb create mode 100644 bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel.json create mode 100644 bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel_url.rb diff --git a/bridgetown-core/lib/bridgetown-core/configurations/vercel.rb b/bridgetown-core/lib/bridgetown-core/configurations/vercel.rb new file mode 100644 index 000000000..2d92afb31 --- /dev/null +++ b/bridgetown-core/lib/bridgetown-core/configurations/vercel.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +copy_file in_templates_dir("vercel.json"), "vercel.json" +copy_file in_templates_dir("vercel_url.rb"), "plugins/builders/vercel_url.rb" diff --git a/bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel.json b/bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel.json new file mode 100644 index 000000000..2b52fa518 --- /dev/null +++ b/bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel.json @@ -0,0 +1,45 @@ +{ + "cleanUrls": true, + "trailingSlash": false, + "redirects": [], + "headers": [ + { + "source": "/(.*)", + "headers": [ + { + "key": "X-Content-Type-Options", + "value": "nosniff" + }, + { + "key": "X-Frame-Options", + "value": "DENY" + }, + { + "key": "X-XSS-Protection", + "value": "1; mode=block" + }, + { + "key": "Referrer-Policy", + "value": "strict-origin" + }, + { + "key": "Permissions-Policy", + "value": "geolocation=(self), microphone=()" + } + ] + }, + { + "source": "/feed.xml", + "headers": [ + { + "key": "Content-Type", + "value": "application/rss+xml" + }, + { + "key": "Cache-Control", + "value": "public, max-age=3600" + } + ] + } + ] +} diff --git a/bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel_url.rb b/bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel_url.rb new file mode 100644 index 000000000..4199edef9 --- /dev/null +++ b/bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel_url.rb @@ -0,0 +1,10 @@ +class VercelUrl < SiteBuilder + def build + hook :site, :pre_render do |s| + next unless ENV["VERCEL_URL"] && ENV["VERCEL_ENV"] != "production" + + Bridgetown.logger.info("Subbing Vercel URL") + site.config.update(url: "https://" + ENV["VERCEL_URL"]) + end + end +end diff --git a/bridgetown-website/src/_docs/bundled-configurations.md b/bridgetown-website/src/_docs/bundled-configurations.md index e2f6a1e70..2adc1e5e2 100644 --- a/bridgetown-website/src/_docs/bundled-configurations.md +++ b/bridgetown-website/src/_docs/bundled-configurations.md @@ -17,6 +17,7 @@ The configurations we include are: - [Bridgetown recommended PostCSS plugins](#bridgetown-recommended-postcss-plugins) (`bt-postcss`) - [Render YAML Configuration](#render-yaml-configuration) (`render`) - [Netlify TOML Configuration](#netlify-toml-configuration) (`netlify`) +- [Vercel JSON Configuration](#vercel-json-configuration) (`vercel`) - [Automated Test Suite using Minitest](#automated-test-suite-using-minitest) (`minitesting`) - [Cypress](#cypress) (`cypress`) @@ -120,6 +121,16 @@ bin/bridgetown configure render bin/bridgetown configure netlify ``` +### Vercel JSON Configuration + +⚙️ Adds a basic configuration to your site for use in [Vercel](https://vercel.com) deployments along with a builder to ensure Bridgetown uses the correct `absolute_url` on preview deployments. + +🛠 **Configure using:** + +```sh +bin/bridgetown configure vercel +``` + ### Automated Test Suite using Minitest ⚙️ Adds a basic test suite using [Minitest](https://rubygems.org/gems/minitest) and Rails DOM assertions for extremely fast verification of your output HTML. Check out [our automated testing guide](/docs/testing#use-ruby-and-minitest-to-test-html-directly) for more info! From bc13ca9790e89ebdc0d5349780fa4454e34e81d5 Mon Sep 17 00:00:00 2001 From: Andrew Mason Date: Fri, 14 Jan 2022 18:00:38 -0700 Subject: [PATCH 2/3] fix: zeitwerk error --- .../lib/bridgetown-core/configurations/vercel/vercel_url.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel_url.rb b/bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel_url.rb index 4199edef9..f1293fb78 100644 --- a/bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel_url.rb +++ b/bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel_url.rb @@ -1,4 +1,4 @@ -class VercelUrl < SiteBuilder +class Builders::VercelUrl < SiteBuilder def build hook :site, :pre_render do |s| next unless ENV["VERCEL_URL"] && ENV["VERCEL_ENV"] != "production" From ba0d56b2867d1420c34e92e3945400bdb25c335d Mon Sep 17 00:00:00 2001 From: Andrew Mason Date: Fri, 14 Jan 2022 18:07:25 -0700 Subject: [PATCH 3/3] style: format --- .../lib/bridgetown-core/configurations/vercel/vercel_url.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel_url.rb b/bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel_url.rb index f1293fb78..3e6f5bdea 100644 --- a/bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel_url.rb +++ b/bridgetown-core/lib/bridgetown-core/configurations/vercel/vercel_url.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + class Builders::VercelUrl < SiteBuilder def build - hook :site, :pre_render do |s| + hook :site, :pre_render do |site| next unless ENV["VERCEL_URL"] && ENV["VERCEL_ENV"] != "production" Bridgetown.logger.info("Subbing Vercel URL") - site.config.update(url: "https://" + ENV["VERCEL_URL"]) + site.config.update(url: "https://#{ENV["VERCEL_URL"]}") end end end