Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gasman committed Jun 27, 2022
0 parents commit 48642ec
Show file tree
Hide file tree
Showing 27 changed files with 818 additions and 0 deletions.
85 changes: 85 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
version: 2

jobs:
flake8:
docker:
- image: circleci/python:3.8
steps:
- checkout
- run: pip install flake8
- run: flake8 wagtail_freezer

prettier:
docker:
- image: circleci/node:16
steps:
- checkout:

- type: cache-restore
keys:
- node-modules-{{ .Branch }}-{{ checksum "package-lock.json" }}
- node-modules-{{ .Branch }}-
- node-modules-master-

- run: npm install
- run: npm run lint

- type: cache-save
key: node-modules-{{ .Branch }}-{{ checksum "package-lock.json" }}
paths:
- "node_modules"

test:
docker:
- image: circleci/python:3.8
steps:
- checkout

- type: cache-restore
keys:
- pip-{{ .Branch }}-
- pip-master-

- run: pip install -e .[testing]

- type: cache-save
key: pip-{{ .Branch }}-{{ epoch }}
paths:
- "~/.cache/pip"

- run: python testmanage.py test

nightly-wagtail-test:
docker:
- image: circleci/python:3.8
steps:
- checkout
- run: git clone git@github.com:wagtail/wagtail.git

- run: pip install -e .[testing]
- run: pip install ./wagtail

- run: python testmanage.py test

- run:
when: on_fail
command: python ./.circleci/report_nightly_build_failure.py

workflows:
version: 2
test:
jobs:
- flake8
- prettier
- test

nightly:
jobs:
- nightly-wagtail-test
triggers:
- schedule:
cron: "0 0 * * *"
filters:
branches:
only:
- master
18 changes: 18 additions & 0 deletions .circleci/report_nightly_build_failure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Called by CircleCI when the nightly build fails.
This reports an error to the #nightly-build-failures Slack channel.
"""
import os
import requests

if 'SLACK_WEBHOOK_URL' in os.environ:
print("Reporting to #nightly-build-failures slack channel")
response = requests.post(os.environ['SLACK_WEBHOOK_URL'], json={
"text": "A Nightly build failed. See " + os.environ['CIRCLE_BUILD_URL'],
})

print("Slack responded with:", response)

else:
print("Unable to report to #nightly-build-failures slack channel because SLACK_WEBHOOK_URL is not set")
8 changes: 8 additions & 0 deletions .circleci/trigger-nightly-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# Triggers a test run against the master version of Wagtail

# This job will is scheduled in the config.yml, this script is here to help test the job

curl -u ${CIRCLE_API_USER_TOKEN}: \
-d build_parameters[CIRCLE_JOB]=nightly-wagtail-test \
https://circleci.com/api/v1.1/project/github/gasman/wagtail-freezer/tree/master
24 changes: 24 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[run]
branch = True
include = wagtail_freezer/*
omit = */migrations/*,*/tests/*

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
def __repr__
if self\.debug

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:

ignore_errors = True
66 changes: 66 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Freezer CI

on:
push:
branches:
- main
- master
- 'stable/**'

pull_request:

jobs:
test-sqlite:
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.7', '3.8', '3.9']
django: ['3.0', '3.1', '3.2']
wagtail: ['2.14', '2.15']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install Tox
run: |
python -m pip install tox
- name: Test
run: |
tox
env:
TOXENV: python${{ matrix.python }}-django${{ matrix.django }}-wagtail${{ matrix.wagtail }}-sqlite

test-postgres:
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.7', '3.8', '3.9']
django: ['3.0', '3.1', '3.2']
wagtail: ['2.14', '2.15']
postgres: ['10.8']

services:
postgres:
image: postgres:${{ matrix.postgres }}
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install Tox
run: |
python -m pip install tox
- name: Test
run: |
tox
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/wagtail_freezer
TOXENV: python${{ matrix.python }}-django${{ matrix.django }}-wagtail${{ matrix.wagtail }}-postgres
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.pyc
/build
/dist
/wagtail_freezer.egg-info
/.coverage
/htmlcov
/.tox
/venv
/.vscode
/site
/test_wagtail_freezer.db
/test-static
/test-media
2 changes: 2 additions & 0 deletions .prettierrc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tabWidth = 4
singleQuote = true
42 changes: 42 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# wagtail-freezer Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.0] - 2022-06-27

### Added

- ...

### Changed

- ...

### Removed

- ...

<!-- TEMPLATE - keep below to copy for new releases -->
<!--
## [x.y.z] - YYYY-MM-DD
### Added
- ...
### Changed
- ...
### Removed
- ...
-->
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Contributing to wagtail-freezer
33 changes: 33 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@



BSD License

Copyright (c) 2022, Matt Westcott
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.

4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include LICENSE *.rst *.txt *.md
graft wagtail_freezer
global-exclude __pycache__
global-exclude *.py[co]
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Wagtail Freezer

Generates static HTML sites from a Wagtail project


[![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)

[![PyPI version](https://badge.fury.io/py/wagtail-freezer.svg)](https://badge.fury.io/py/wagtail-freezer)
[![wagtail-freezer CI](https://github.com/gasman/wagtail-freezer/actions/workflows/test.yml/badge.svg)](https://github.com/gasman/wagtail-freezer/actions/workflows/test.yml)

## Links

- [Documentation](https://github.com/gasman/wagtail-freezer/blob/main/README.md)
- [Changelog](https://github.com/gasman/wagtail-freezer/blob/main/CHANGELOG.md)
- [Contributing](https://github.com/gasman/wagtail-freezer/blob/main/CHANGELOG.md)
- [Discussions](https://github.com/gasman/wagtail-freezer/discussions)
- [Security](https://github.com/gasman/wagtail-freezer/security)

## Supported versions

- Python 3.7 - 3.10
- Django 3.x
- Wagtail 3.x

## Installation

- `pip install wagtail-freezer`
- Add `"wagtail_freezer"` to INSTALLED_APPS
- Add a `FREEZER_BUILD_DIR` setting indicating where the static files will be output. To write into a folder named `build` at the project root, use:

FREEZER_BUILD_DIR = os.path.join(BASE_DIR, "build")

## Usage

Run `./manage.py buildstaticsite`. This will generate one folder per site within FREEZER_BUILD_DIR, with subfolders making up the page tree and the pages themselves saved as `index.html` at the appropriate point.

While building the static files, wagtail-freezer will scan the HTML for any `href` or `src` attributes that reference files under `STATIC_URL` or `MEDIA_URL`, and copy these files to corresponding folders under the site root. This step only takes place if `STATIC_URL` or `MEDIA_URL` are local URLs beginning with '/'.

If you have additional static / media files that can't be found by parsing HTML (for example, images referenced within CSS, JavaScript or JSON), you can provide a `freezer_follow_urls` method on the page model that returns a list of media / static URLs to be followed:

```python
class HomePage(Page):
@property
def freezer_follow_urls(self):
urls = ['/static/images/background.jpg']
for item in self.playlist.select_related('video'):
urls.append(item.video.url)
return urls
```

## Deploying

When you're happy with how the local static site works (test it by running `python -m http.server` from the root folder), you can deploy it to Amazon S3 by installing the AWS command line tool (`pip install awscli`), creating a bucket [configured for static website hosting](https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteHosting.html), and running:

aws s3 sync build/localhost s3://mysite.example.com/ --acl public-read


## Limitations

wagtail-freezer was created as a "minimum viable product" substitute for static site generators such as [django-bakery](https://django-bakery.readthedocs.io/), which at the time of writing are lagging behind in support for current Django (and Wagtail) versions. It has only been tested against very simple sites, and will probably not work with custom URL routes (RoutablePageMixin), pages with multiple preview modes (wagtail.contrib.forms, although that's not too usable on a static site anyhow), non-standard middlewares and no doubt lots of other things. Use at your own risk!
5 changes: 5 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Security

We take the security of Wagtail, and related packages we maintain, seriously. If you have found a security issue with any of our projects please email us at security@wagtail.org so we can work together to find and patch the issue. We appreciate responsible disclosure with any security related issues, so please contact us first before creating a Github issue.

If you want to send an encrypted email (optional), the public key ID for security@wagtail.org is 0xbed227b4daf93ff9, and this public key is available from most commonly-used keyservers.
Loading

0 comments on commit 48642ec

Please sign in to comment.