mirror of
https://github.com/hendricius/the-sourdough-framework
synced 2025-11-14 15:11:11 -06:00
Validate website format (#304)
* Validate website format This validates the format of the website and throws an error if something is fishy. * Remove -j flag * clean build * Clean cache in between
This commit is contained in:
committed by
GitHub
parent
8250789855
commit
9e8acf257d
32
.github/workflows/release-book-website.yml
vendored
32
.github/workflows/release-book-website.yml
vendored
@@ -49,22 +49,6 @@ jobs:
|
||||
aws_bucket: ${{ secrets.AWS_BUCKET_BOOK }}
|
||||
source_dir: book/release
|
||||
destination_dir: release
|
||||
- name: Bake the website
|
||||
uses: addnab/docker-run-action@v3
|
||||
with:
|
||||
image: ${{ env.IMAGE }}
|
||||
options: -v ${{ github.workspace }}:/app
|
||||
run: |
|
||||
cd /app/book
|
||||
make website
|
||||
- name: Release baked website to S3
|
||||
uses: shallwefootball/s3-upload-action@master
|
||||
with:
|
||||
aws_key_id: ${{ secrets.AWS_KEY_ID }}
|
||||
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
|
||||
aws_bucket: ${{ secrets.AWS_BUCKET_WEBSITE }}
|
||||
source_dir: website/static_website_html
|
||||
destination_dir: static_html_root
|
||||
- name: Upload book Artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
@@ -73,6 +57,22 @@ jobs:
|
||||
book/book_serif/book.log
|
||||
book/book_serif/book.pdf
|
||||
book/book-epub/book.epub
|
||||
- name: Bake the website
|
||||
uses: addnab/docker-run-action@v3
|
||||
with:
|
||||
image: ${{ env.IMAGE }}
|
||||
options: -v ${{ github.workspace }}:/app
|
||||
run: |
|
||||
cd /app/book
|
||||
make mrproper && make website
|
||||
- name: Release baked website to S3
|
||||
uses: shallwefootball/s3-upload-action@master
|
||||
with:
|
||||
aws_key_id: ${{ secrets.AWS_KEY_ID }}
|
||||
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
|
||||
aws_bucket: ${{ secrets.AWS_BUCKET_WEBSITE }}
|
||||
source_dir: website/static_website_html
|
||||
destination_dir: static_html_root
|
||||
- name: Upload website Artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
|
||||
16
.github/workflows/test-book-website.yml
vendored
16
.github/workflows/test-book-website.yml
vendored
@@ -40,14 +40,6 @@ jobs:
|
||||
run: |
|
||||
cd /app/book
|
||||
make -j build_serif_pdf build_ebook
|
||||
- name: Test building website
|
||||
uses: addnab/docker-run-action@v3
|
||||
with:
|
||||
image: ${{ env.IMAGE }}
|
||||
options: -v ${{ github.workspace }}:/app
|
||||
run: |
|
||||
cd /app/book
|
||||
make -j website
|
||||
- name: Upload book Artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
@@ -56,6 +48,14 @@ jobs:
|
||||
book/book_serif/book.log
|
||||
book/book_serif/book.pdf
|
||||
book/book-epub/book.epub
|
||||
- name: Test building website
|
||||
uses: addnab/docker-run-action@v3
|
||||
with:
|
||||
image: ${{ env.IMAGE }}
|
||||
options: -v ${{ github.workspace }}:/app
|
||||
run: |
|
||||
cd /app/book
|
||||
make mrproper && make website
|
||||
- name: Upload website Artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
|
||||
@@ -5,6 +5,8 @@ require 'nokogiri'
|
||||
# several optimisations on the HTML. Nokogiri is used to facilitate the
|
||||
# modifications.
|
||||
|
||||
class InvalidWebsiteFormat < StandardError; end
|
||||
|
||||
class ModifyBuild
|
||||
HOST = "https://www.the-sourdough-framework.com".freeze
|
||||
|
||||
@@ -15,6 +17,8 @@ class ModifyBuild
|
||||
def build
|
||||
build_latex_html
|
||||
create_sitemap
|
||||
rescue InvalidWebsiteFormat => e
|
||||
raise e
|
||||
end
|
||||
|
||||
private
|
||||
@@ -42,6 +46,7 @@ class ModifyBuild
|
||||
|
||||
def modify_file(filename)
|
||||
orig_text = File.read(filename, encoding: "UTF-8")
|
||||
validate_file(orig_text)
|
||||
text = fix_double_slashes(orig_text)
|
||||
text = fix_navigation_bar(text)
|
||||
text = fix_titles(text)
|
||||
@@ -101,6 +106,18 @@ class ModifyBuild
|
||||
text.gsub(/\/\//, "/")
|
||||
end
|
||||
|
||||
# Sometimes for whatever reason the make4ht input produces files that are
|
||||
# improperly formatted. This validator will go through the files and do a
|
||||
# couple of basic checks to see if the files are in the format we expect. If
|
||||
# not an exception is caused.
|
||||
def validate_file(text)
|
||||
doc = build_doc(text)
|
||||
stylesheets = doc.css("link[rel='stylesheet']").map{|attr| attr["href"] }
|
||||
has_all_styles = %w(book.css style.css).all? { |required_stylesheet| stylesheets.include?(required_stylesheet) }
|
||||
raise InvalidWebsiteFormat.new("No style tag style.css found in the website") unless has_all_styles
|
||||
true
|
||||
end
|
||||
|
||||
def fix_navigation_bar(text)
|
||||
doc = build_doc(text)
|
||||
elements = [doc.search('.chapterToc'), doc.search('.sectionToc'), doc.search('.subsectionToc')].flatten
|
||||
|
||||
Reference in New Issue
Block a user