{{ param }}
``` -------------------------------- ### Low-level Boot Customization with Bundler Setup Source: https://www.bridgetownrb.com/docs/configuration/initializers Add a `config/boot.rb` file to run Ruby code at the earliest possible moment during `bridgetown` executable startup. Ensure Bundler is set up correctly. ```ruby # Normally the following is run automatically, so by adding config/boot.rb, you should include # this Bundler setup: Bundler.setup(:default, Bridgetown.env) # Now you can require a gem which adds a command to `bridgetown` via Samovar: require "some_gem_here" # Or require your own Ruby file: require_relative "../ruby_code_file.rb" ``` -------------------------------- ### Create a New Collection with Custom Layout Source: https://www.bridgetownrb.com/docs/plugins/external-apis You can create new collections on the fly and use existing layouts. This example creates a 'blogish' collection for a fake blog post. ```ruby add_resource :blogish, "fake-blog-post.html" do layout :post title "I'm a blog post…sort of" date "2020-05-17" content "I might look like a blog post, but I'm not!
" end ``` -------------------------------- ### Configure Tutorials Collection with Custom Metadata (YAML) Source: https://www.bridgetownrb.com/docs/collections Define a 'tutorials' collection with output enabled and custom metadata 'name' in Bridgetown's configuration using YAML. ```yaml collections: tutorials: output: true name: Terrific Tutorials ``` -------------------------------- ### Use Tag with Instance Method Source: https://www.bridgetownrb.com/docs/plugins/tags Example of using the `upcase` tag block, which converts its content to uppercase. ```html {% upcase %} i am upper case {% endupcase %} ``` -------------------------------- ### Access Convertible Object in Converter Source: https://www.bridgetownrb.com/docs/plugins/converters This example shows how to access the `convertible` object within the `convert` method to get more context about the file being processed. This allows you to include information about the source document or layout in the converted output. ```ruby def convert(content, convertible) content + " — brought to you by the #{convertible.class} object." end ``` -------------------------------- ### Configure Bridgetown PostCSS Plugins Source: https://www.bridgetownrb.com/docs/bundled-configurations Installs and configures recommended PostCSS plugins, including `postcss-mixins`, `postcss-color-mod-function`, `cssnano`, and `postcss-preset-env`. This overwrites your `postcss.config.js` file. ```bash bin/bridgetown configure bt-postcss ``` -------------------------------- ### Configure Tutorials Collection with Custom Metadata (Ruby) Source: https://www.bridgetownrb.com/docs/collections Define a 'tutorials' collection with output enabled and custom metadata 'name' in Bridgetown's configuration using Ruby. ```ruby Bridgetown.configure do collections do tutorials do output true name "Terrific Tutorials" end end end ``` -------------------------------- ### Previewing Unpublished Content Source: https://www.bridgetownrb.com/docs/migrating/jekyll To preview content marked as unpublished locally, use the `--unpublished` or `-U` command-line option when starting the server. ```bash bin/bridgetown start --unpublished ``` -------------------------------- ### Create a Local Custom Plugin with SiteBuilder Source: https://www.bridgetownrb.com/docs/plugins Define a local custom plugin by subclassing `SiteBuilder` and implementing the `build` method. This example registers a Liquid tag. ```ruby # plugins/builders/add_some_tags.rb class Builders::AddSomeTags < SiteBuilder def build liquid_tag "cool_stuff", :cool_tag end def cool_tag(attributes, tag) "This is so cool!" end end ``` -------------------------------- ### Install ruby-build Plugin for rbenv Source: https://www.bridgetownrb.com/docs/installation/fedora Installs the ruby-build plugin for rbenv, enabling the installation of different Ruby versions. ```bash git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc source ~/.bashrc ``` -------------------------------- ### Load Site Configuration and Initialize Site Object Source: https://www.bridgetownrb.com/docs/plugins/commands Use the ConfigurationOverridable mixin to load site configuration, potentially overriding settings with command-line options. Then, initialize a Bridgetown::Site object and optionally run its setup hooks and read/generate content. ```ruby config = configuration_with_overrides(options) config.run_initializers! context: :static site = Bridgetown::Site.new(config) # optionally run setup hooks and read in content if needed: site.reset site.read site.generate ``` -------------------------------- ### Install Bridgetown Gem Source: https://www.bridgetownrb.com/docs Installs the Bridgetown gem and its dependencies. Use the -N flag to install all necessary gems. ```ruby gem install bridgetown -N ``` -------------------------------- ### Basic Roda App Configuration in Bridgetown Source: https://www.bridgetownrb.com/docs/roda This is the default Roda application setup in Bridgetown, integrating the bridgetown_server plugin and Bridgetown's routing system. ```ruby class RodaApp < Roda plugin :bridgetown_server route do |r| r.bridgetown end end ``` -------------------------------- ### Configure Static Site Deployment on Dokku Source: https://www.bridgetownrb.com/docs/deployment Create an empty .static file to indicate a static site deployment for Dokku. ```text .static ``` -------------------------------- ### Create First Island Entrypoint (breezy.js) Source: https://www.bridgetownrb.com/docs/islands Define your first island component in `src/_islands/breezy.js`. This JavaScript file and its imports are self-contained and not bundled with your main JavaScript. ```javascript class BreezyDay extends HTMLElement { static { customElements.define("breezy-day", this) } connectedCallback() { this.textContent = "Welcome to your first island." } } ``` -------------------------------- ### Apply Automation to New Site Source: https://www.bridgetownrb.com/docs/automations Use the `--apply` or `-a` flag with `bridgetown new` to apply an automation script during site creation. ```bash bridgetown new mysite --apply=/path/to/automation.rb ``` -------------------------------- ### Copy Plugin Layouts to Site Source: https://www.bridgetownrb.com/docs/commands/plugins An example of using `bridgetown plugins cd` to copy all layouts from a plugin's `Layouts` directory into your site's `src/_layouts` folder. Remember to type `exit` when finished. ```bash bridgetown plugins cd AwesomePlugin/Layouts cp -r * $BRIDGETOWN_SITE/src/_layouts exit ``` -------------------------------- ### Create Initializers File for New Configuration Format Source: https://www.bridgetownrb.com/docs/installation/upgrade Create this file to opt into the new configuration format and disable legacy mode. This file replaces the need for the `bridgetown_plugins` Gemfile group. ```ruby Bridgetown.configure do |config|\n # add configuration here\nend ``` -------------------------------- ### Apply Automation to Existing Site Source: https://www.bridgetownrb.com/docs/automations Use the `bin/bridgetown apply` command to run an automation script on an existing site. ```bash bin/bridgetown apply /path/to/automation.rb ``` -------------------------------- ### Install Fedora Dependencies for Ruby Source: https://www.bridgetownrb.com/docs/installation/fedora Installs necessary development tools and libraries required for Ruby compilation on Fedora. ```bash sudo dnf install git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel ``` -------------------------------- ### Add Query String Parameters to GET Request Source: https://www.bridgetownrb.com/docs/plugins/external-apis Pass query string parameters to the GET request endpoint using keyword arguments. ```ruby def build get "https://example.com", test: 123 do |data| # data from https://example.com?test=123 end end ``` -------------------------------- ### Configure Bridgetown with Initializers Source: https://www.bridgetownrb.com/docs/configuration The `config/initializers.rb` file allows for expressive configuration using Ruby, including environment-specific settings and plugin initialization. ```ruby Bridgetown.configure do |config| init :dotenv config.autoload_paths << "jobs" url "https://www.bridgetownrb.com" permalink "pretty" timezone "America/Los_Angeles" template_engine "serbea" collections do docs do output true permalink "/:collection/:path.*" name "Documentation" end end if Bridgetown.env.development? unpublished true end only :server do init :mail, password: ENV["SENDGRID_API_KEY"] end end ``` -------------------------------- ### Make a GET Request and Store Data Source: https://www.bridgetownrb.com/docs/plugins/external-apis Make a GET request within a site hook and store the parsed JSON data in `site.data`. ```ruby def build hook :site, :post_read do get url do |data| site.data[:remote_api_info] = data end end end ``` -------------------------------- ### Initialize SSR and Routes Plugins with Initializers Source: https://www.bridgetownrb.com/docs/installation/upgrade Replace `plugin` statements in `server/roda_app.rb` with `init` statements in the initializers file for SSR and dynamic routes plugins. ```ruby Bridgetown.configure do |config|\n init :ssr\n init :"bridgetown-routes"\nend ``` -------------------------------- ### Configure Minitesting for Bridgetown Source: https://www.bridgetownrb.com/docs/testing Run this command to add Minitest and RackTest gems and set up the test environment. ```bash bin/bridgetown configure minitesting ``` -------------------------------- ### Front Matter Example for Post Metadata Source: https://www.bridgetownrb.com/docs/first-steps-for-newbies Example of front matter for a post, defining metadata like order, title, section, description, and category. This data can be accessed via `post.data`. ```yaml --- order: 45 title: First Steps for Newbies top_section: Setup description: If Bridgetown is your first web framework category: first-steps --- ``` -------------------------------- ### Initialize SSR and Dynamic Routes Source: https://www.bridgetownrb.com/docs/configuration/initializers Use the `init` command to enable Bridgetown's Server-Side Rendering (SSR) and dynamic routing features. The `dotenv` initializer is also recommended. ```ruby init :ssr, sessions: true # the dotenv initializer is also recommended, more on that below # optional: init :"bridgetown-routes" ``` -------------------------------- ### Install Latest Ruby 3.x with Mise Source: https://www.bridgetownrb.com/docs/installation/windows Installs the latest available Ruby version within the 3.x series using Mise and sets it as the global default. This command ensures a compatible Ruby environment for Bridgetown. ```bash mise use --global ruby@3 ``` -------------------------------- ### Verify rbenv Installation Source: https://www.bridgetownrb.com/docs/installation/ubuntu Check if the rbenv command is recognized by your shell. ```bash type rbenv ``` -------------------------------- ### Apply Default Automation Source: https://www.bridgetownrb.com/docs/automations If no automation file is specified, `bin/bridgetown apply` looks for `bridgetown.automation.rb` in the current directory. ```bash vim bridgetown.automation.rb # save an automation script bin/bridgetown apply ``` -------------------------------- ### Update Package List Source: https://www.bridgetownrb.com/docs/installation/ubuntu Update your system's package list before installing new software. ```bash sudo apt update ``` -------------------------------- ### Configure Custom Taxonomy in Bridgetown Config Source: https://www.bridgetownrb.com/docs/resources Example of configuring a custom 'genre' taxonomy in the `bridgetown.config.yml` file. ```yaml # bridgetown.config.yml taxonomies: genre: key: genres title: "Musical Genre" other_metadata: "can go here!" ``` -------------------------------- ### Setup Primer Builder in Bridgetown Source: https://www.bridgetownrb.com/docs/components/view-component This Ruby code sets up a SiteBuilder to load Primer View Components, configure Zeitwerk for autoloading, and ensure Primer's engine configuration is applied to the Rails shim. It's designed to run only once in Bridgetown's watch mode. ```ruby require "action_dispatch" require "rails/engine" require "primer/view_components/engine" class Builders::PrimerBuilder < SiteBuilder def build site.config.loaded_primer ||= begin primer_loader = Zeitwerk::Loader.new Primer::ViewComponents::Engine.config.eager_load_paths.each do |path| primer_loader.push_dir path end primer_loader.setup Rails.application.config = Primer::ViewComponents::Engine.config true end end end ``` -------------------------------- ### Define Taxonomy Front Matter Source: https://www.bridgetownrb.com/docs/resources Example of how to define categories and tags using front matter in Bridgetown resources. ```yaml categories: - category 1 - another category 2 tags: - blessed - super awesome ``` -------------------------------- ### Enable Liquid Profiling Source: https://www.bridgetownrb.com/docs/configuration/options Use the `--profile` flag or set `profile: BOOL` to generate a Liquid rendering profile for performance analysis. ```bash profile: BOOL --profile ``` -------------------------------- ### Variable Interpolation in Translations (ERB) Source: https://www.bridgetownrb.com/docs/internationalization Pass variables to the `t` helper to interpolate values into translations, as shown in this ERB example. ```erb <%= t("products.price", price: resource.data.price) %> ``` -------------------------------- ### Configure Lit Source: https://www.bridgetownrb.com/docs/bundled-configurations Sets up Lit, the Lit SSR Renderer plugin, and includes an example component. Lit components are native web components ideal for shareable components and sites. ```bash bin/bridgetown configure lit ``` -------------------------------- ### Change Directory Source: https://www.bridgetownrb.com/docs Navigates into the newly created Bridgetown site directory. ```bash cd mysite ``` -------------------------------- ### Create File Automation Source: https://www.bridgetownrb.com/docs/automations This automation script creates a new file named `netlify.toml` with specified build configurations. ```ruby create_file "netlify.toml" do <<~NETLIFY [build] command = "bin/bridgetown deploy" publish = "output" [build.environment] NODE_VERSION = "22" [context.production.environment] BRIDGETOWN_ENV = "production" NETLIFY end ``` -------------------------------- ### Dockerfile for Static Bridgetown Site Deployment Source: https://www.bridgetownrb.com/docs/deployment This Dockerfile builds a production-ready static version of your Bridgetown site. It uses a multi-stage build process, first compiling the site with Ruby and Node.js, then serving the output using a lightweight HTTP server. ```dockerfile FROM combos/ruby_node:3_22 AS builder ENV BRIDGETOWN_ENV=production WORKDIR /opt/src COPY . . RUN bundle install && npm install && bundle exec bridgetown deploy FROM lipanski/docker-static-website:latest COPY --from=builder /opt/src/output . CMD ["/busybox-httpd", "-f", "-v", "-p", "4000"] ``` -------------------------------- ### Define a Navbar Liquid Component Source: https://www.bridgetownrb.com/docs/components/liquid This is an example of a Liquid component definition for a navbar, using placeholders for logo and navigation items. ```liquid ``` -------------------------------- ### Configure GitHub Pages Deployment Source: https://www.bridgetownrb.com/docs/bundled-configurations Sets up a GitHub Action for hosting your Bridgetown site directly on GitHub. Ensure your `base_path` is configured correctly after running this command. ```bash bin/bridgetown configure gh-pages ``` -------------------------------- ### Configure Bridgetown with Initializers Source: https://www.bridgetownrb.com/docs/configuration/initializers Use the `Bridgetown.configure` block to set options, load initializers, and define context-specific configurations. This is the primary way to customize your site's behavior. ```ruby Bridgetown.configure do |config| init :dotenv config.autoload_paths << "jobs" init :ssr do sessions true setup -> site do # perform site setup tasks only in the server context end end init :"bridgetown-routes" # you can configure site settings here just like you would in bridgetown.config.yml permalink "pretty" timezone "America/Los_Angeles" # some initializers accept additional options init :stripe, api_key: ENV["STRIPE_API_KEY"] only :server do # code which runs only in server context init :parse_routes # you can also provide initializer options in block DSL form: init :mail do password ENV["SENDGRID_API_KEY"] end end only :static, :console do # code which runs only in static and console contexts end only :rake do # code which runs only in the Rake context end except :static, :console do # you can define hooks within your initializers file: hook :site, :after_init do |site| # runs after a site is initialized in server, Rake, etc. contexts, but not static or console end end end Bridgetown.initializer :stripe do |api_key:| Bridgetown.logger.info "Stripe:", "Setting the API key" Stripe.api_key = api_key end ``` -------------------------------- ### Define Product Report Route Source: https://www.bridgetownrb.com/docs/routes Defines a GET route for /reports/:id that captures an integer ID and maps it to a controller. ```ruby class Routes::Reports < Bridgetown::Rack::Routes route do |r| r.on "reports" do # route: /reports/:id r.get Integer do |id| Controllers::Reports::Show.new(id:) end end end end ``` -------------------------------- ### Get All Descendants of a Class Source: https://www.bridgetownrb.com/docs/plugins/foundation-gem The `descendants` class method returns a flattened array of all named, globally accessible descendants of a class. ```ruby MyClass.descendants ``` -------------------------------- ### Copy Theme Files to Site Repo Source: https://www.bridgetownrb.com/docs/themes Use the `bridgetown plugins cd` command to copy files from a theme into your site's repository directly. ```bash bridgetown plugins cd ``` -------------------------------- ### Switch from Yarn to NPM Source: https://www.bridgetownrb.com/docs/installation/upgrade To switch to NPM as your default package manager, delete `yarn.lock`, run `npm install`, and commit `package-lock.json`. ```bash npm install ``` -------------------------------- ### Context-Specific Configuration (Except Static) Source: https://www.bridgetownrb.com/docs/configuration/initializers Applies configuration settings to all contexts except for static builds. Use `except` to exclude specific initialization contexts. ```ruby except :static do puts "I get run for any context other than a static build!" end ``` -------------------------------- ### Layout Variables Example Source: https://www.bridgetownrb.com/docs/layouts Shows how to set and access variables within a layout's front matter using the `layout` variable. This allows for dynamic content within the layout itself. ```liquid --- city: San Francisco ---{{ layout.data.city }}
{{ content }} ``` -------------------------------- ### Build Movie Collection Layout with ERB Source: https://www.bridgetownrb.com/docs/resources Example of an ERB layout for a movie collection, demonstrating how to display resource data and relations. ```htmlStarring:
Released by <%= link_to resource.relations.studio.name, resource.relations.studio %>
``` -------------------------------- ### Configure Resource Relations in Bridgetown Config Source: https://www.bridgetownrb.com/docs/resources Example of configuring one-to-many and many-to-one resource relations between 'actors', 'movies', and 'studios' collections. ```yaml collections: actors: output: true relations: has_many: movies movies: output: true relations: belongs_to: - actors - studio studios: output: true relations: has_many: movies ``` -------------------------------- ### Use Custom Taxonomy in Resource Front Matter Source: https://www.bridgetownrb.com/docs/resources Example of assigning values to a custom 'genres' taxonomy in resource front matter. ```yaml genres: - Jazz - Big Band ``` -------------------------------- ### Navigate to Plugin Source Directory Source: https://www.bridgetownrb.com/docs/commands/plugins Use `bridgetown plugins cd