Jigsaw Static Site Framework

website·Indexed 36 days ago

https://jigsaw.tighten.co/docs/installation/

A framework for rapidly building static sites using modern tooling. Jigsaw allows developers to create content using Markdown and Blade templates, featuring powerful collection management, site variables, and Vite integration for asset compilation. It supports local development via .env configuration and deployment to platforms like GitHub Pages and Netlify.

Tokens
11.9K
Snippets
80
Records
94
Agent score
69%

What's inside Jigsaw

  1. Manage site content source and formats in Jigsaw

    All site content must be stored within the source directory. Jigsaw supports multiple authoring formats for content files, including Laravel's Blade templating language, Markdown, and various other file types.
  2. Understand Jigsaw Pretty URL rendering

    By default, Jigsaw implements 'Pretty URLs' by rendering any Blade file that is not named index.blade.php as an index.html file within a subfolder named after the original file. This allows pages to be accessed via a directory path (e.g., http://example.com/about-us/) rather than a direct .html file path (e.g., http://example.com/about-us.html). For example, source/about-us.blade.php is rendered to build/about-us/index.html.
  3. Use Blade templating in Jigsaw

    Jigsaw integrates the Blade templating engine, allowing developers to use the same syntax used in Laravel applications for static site layouts.
    @extends('_layouts.master')
    
    @section('body')
      <h1>Hello World</h1>
    @endsection
  4. Create collection items without individual pages

    Parent templates are optional. If you only need collection data to be used on a shared page (e.g., a staff directory on an 'About Us' page) and do not need a dedicated URL for each item, omit the extends key from the YAML front matter or the @extends directive from the Blade file.
  5. Hook into Jigsaw build events

    Jigsaw provides three primary events that allow you to run custom PHP code at different stages of the build process. These events are registered in bootstrap.php using the $events object.
    // Example of registering listeners in bootstrap.php
    $events->beforeBuild(function ($jigsaw) {
       // Runs before source files are processed
    });
    
    $events->afterCollections(function ($jigsaw) {
       // Runs after collections are processed, but before output files are built
    });
    
    $events->afterBuild(function ($jigsaw) {
       // Runs after the build is complete and files are written to the build directory
    });
  6. Retrieve page metadata using the $page object

    In Jigsaw, the $page object provides several get functions to retrieve metadata about the current page. These methods allow you to dynamically access file paths, URLs, and system timestamps for the page being processed.
    // Get the path to the current page, relative to the site root
    $page->getPath();
    
    // Get the relative path (parent directories) of the current page, relative to the site root
    $page->getRelativePath();
    
    // Get the full URL to the item (requires baseUrl to be defined in config.php)
    $page->getUrl();
    
    // Get the filename of the page without the extension (e.g., 'my-first-page')
    $page->getFilename();
    
    // Get the file extension (e.g., 'md')
    $page->getExtension();
    
    // Get the last modified time of the file as a Unix timestamp
    $page->getModifiedTime();
  7. Generate individual pages for collection items

    To generate a dedicated page for each item in a collection, specify a parent template. This is done by adding an extends key to the YAML front matter of a Markdown file or using the @extends directive in a Blade file.
    ---
    extends: _layouts.post
    title: My First Blog Post
    author: Keith Damiani
    date: 2017-03-23
    section: content
    ---
    
    This post is profoundly interesting.
    {{-- _layouts/post.blade.php --}}
    @extends('_layouts.master')
    
    @section('body')
        <h1>{{ $page->title }}</h1>
        <p>By {{ $page->author }} • {{ date('F j, Y', $page->date) }}</p>
    
        @yield('content')
    @endsection
  8. Access and filter collection items in Blade templates

    Collections are available in Blade templates as variables named after the collection. These variables are Illuminate Collection objects, meaning they support standard Laravel collection methods like count(), filter(), and where().
    {{-- List all post titles --}}
    <p>Total of {{ $posts->count() }} posts</p>
    <ul>
    @foreach ($posts as $post)
        <li>{{ $post->title }}</li>
    @endforeach
    </ul>
    
    {{-- Filter posts by author --}}
    @php
        $authorPosts = $posts->filter(function ($value, $key) use ($page) {
            return $value->author == $page->author;
        });
    @endphp
    
    @if ($authorPosts->count() > 0)
        <ul>
            @foreach ($authorPosts as $post)
                <li>{{ $post->title }}</li>
            @endforeach
        </ul>
    @endif
  9. Format dates from Markdown front matter in Blade

    Jigsaw's YAML processor converts dates in front matter into integer timestamps. To display these dates in a specific format within a Blade template, use PHP's date() function.
    ---
    date: 2018-02-16
    ---

    <!-- In Blade template --> <p>The formatted date is {{ date('F j, Y', $page->date) }}</p>

  10. Preview the site with Vite for hot reloading

    Run the npm run dev command to start the development environment. This setup uses Vite to handle JavaScript and CSS assets (located in source/_assets/js/app.js and source/_assets/css/app.css) and provides Hot Module Replacement (HMR).

    When using this method, Jigsaw generates static HTML in the /build_local directory and automatically triggers a full browser page reload whenever Markdown or Blade files are modified.

    npm run dev
  11. Deploy Jigsaw site to Netlify

    Deploy Jigsaw to Netlify by creating a netlify.toml configuration file in your project root and connecting your repository to the Netlify app for continuous deployment.
    [build]
    command = "npm run build"
    publish = "build_production"
  12. Create pages using Markdown in Jigsaw

    To create pages using Markdown instead of Blade, use the .markdown or .md file extension. You must specify the layout to extend and the section to populate within the YAML front matter.
    ---
    extends: _layouts.master
    section: content
    ---
    
    # My awesome heading!
    
    My awesome content!