Skip to content

Commit

Permalink
Merge pull request #99 from carstene1ns/update/cleanup
Browse files Browse the repository at this point in the history
Update/Cleanup
  • Loading branch information
Ghabry authored Apr 24, 2024
2 parents 31802e1 + cf34adf commit fe88369
Show file tree
Hide file tree
Showing 33 changed files with 87 additions and 65 deletions.
8 changes: 2 additions & 6 deletions .netlify/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
set -e

if [ "x$1" == "xredirect" ]; then
# remove content
rm -rf content
# remove pages content
find content/ -type f -a \( -name '*.md' -o -name '*.html' \) --delete

# make redirect page default
mkdir content
cp .netlify/redirect.md content/index.md

# relocate assets
sed -r 's#(href|src)="/#\1="https://easyrpg.org/#g' -i layouts/default.slim
fi

# correct url
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gem 'typogruby' # text enhancements
gem 'rouge' # syntax highlighting
gem 'slim' # templates
gem 'builder' # xml sitemaps
gem 'yuicompressor' # css/js uglifying
gem 'terser' # js uglifying
gem 'ruby-xxHash' # for cache busting

group :nanoc do
Expand Down
6 changes: 4 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ GEM
eventmachine (>= 0.12.9)
http_parser.rb (~> 0)
eventmachine (1.2.7)
execjs (2.9.1)
ffi (1.16.3)
google-protobuf (3.25.3-x86_64-linux)
http_parser.rb (0.8.0)
Expand Down Expand Up @@ -126,6 +127,8 @@ GEM
set (~> 1.0)
stringio (3.1.0)
temple (0.10.3)
terser (1.2.2)
execjs (>= 0.3.0, < 3)
tilt (2.3.0)
tty-color (0.6.0)
tty-command (0.10.1)
Expand All @@ -139,7 +142,6 @@ GEM
nokogiri (~> 1.6)
rexml (~> 3.2)
webrick (1.8.1)
yuicompressor (1.3.3)
zeitwerk (2.6.13)

PLATFORMS
Expand All @@ -157,9 +159,9 @@ DEPENDENCIES
rouge
ruby-xxHash
slim
terser
typogruby
w3c_validators
yuicompressor

RUBY VERSION
ruby 3.0.5p211
Expand Down
70 changes: 35 additions & 35 deletions Rules
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env ruby

require 'ruby-xxhash'

preprocess do
hide_items_from_sitemap
write_sitemap_file
end

# all pages
compile '/**/*.{html,md}' do
filter :erb
filter :kramdown, auto_ids: false if item.identifier =~ '/**/*.md'
Expand All @@ -17,52 +16,53 @@ compile '/**/*.{html,md}' do
filter :tidy if @config[:prod]
end

compile '/{css/*.scss,js/*.js}' do
ext = "." + item.identifier.ext
if ext == '.scss'
filter :dart_sass, {
:syntax => :scss,
:style => (@config[:prod] ? :compressed : :expanded)
}
ext = ".css"
# home and error page
route '/*.{html,md}' do
item.identifier.without_ext + '.html'
end

route '/**/*.{html,md}' do
# section home
if item.identifier =~ '**/index.*'
item.identifier.without_ext + ".html"
# every other page
else
item.identifier.without_ext + '/index.html'
end
end

# compress and use a hash to avoid caching issues
ignore '/css/{vendor,bits}/*'
compile '/css/*.scss' do
filter :dart_sass, :style => (@config[:prod] ? :compressed : :expanded)
end

compile '/js/*.js' do
if @config[:prod]
filter :yui_compressor, :type => :js if ext == ".js"
checksum = XXhash.xxh32(File.read(item[:filename]), 0xEA51)
write item.identifier.without_ext + '-' + checksum.to_s + ".min" + ext
filter :terser
end
end

route '/{js/*.js,css/*.scss}' do
ext = item.identifier.ext == 'scss' ? '.css' : '.' + item.identifier.ext
if @config[:prod]
item.identifier.without_ext + '-' + asset_hash(item) + '.min' + ext
else
write item.identifier.without_ext + ext
item.identifier.without_ext + ext
end
end
ignore '/css/**/*'

compile '/sitemap.xml' do
filter :erb
write '/sitemap.xml'
end

compile '/htaccess.txt' do
write '/.htaccess'
end

route '/**/*.{html,md}' do
# homepage
if item.identifier =~ '/index.*'
'/index.html'
# error page
elsif item.identifier =~ '/404.*'
'/404.html'
# section home
elsif item.identifier =~ '**/index.*'
item.identifier.without_ext + ".html"
# every other page
else
item.identifier.without_ext + '/index.html'
end
# duplicate some files
compile '/ads.txt' do
write item.identifier
write "/app-ads.txt"
end

# copy the rest over
passthrough '/**/*'

layout '/**/*.slim', :slim, {
Expand Down
Binary file removed content/android-chrome-192x192.png
Binary file not shown.
Binary file removed content/android-chrome-512x512.png
Binary file not shown.
1 change: 0 additions & 1 deletion content/app-ads.txt

This file was deleted.

Binary file removed content/apple-touch-icon-precomposed.png
Binary file not shown.
Binary file removed content/apple-touch-icon.png
Binary file not shown.
5 changes: 4 additions & 1 deletion content/browserconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/mstile-150x150.png"/>
<square70x70logo src="/images/icons/mstile-70x70.png"/>
<square150x150logo src="/images/icons/mstile-150x150.png"/>
<square310x310logo src="/images/icons/mstile-310x310.png"/>
<wide310x150logo src="/images/icons/mstile-310x150.png"/>
<TileColor>#2d631d</TileColor>
</tile>
</msapplication>
Expand Down
Binary file removed content/favicon-16x16.png
Binary file not shown.
Binary file removed content/favicon-32x32.png
Binary file not shown.
3 changes: 0 additions & 3 deletions content/htaccess.txt

This file was deleted.

Binary file added content/images/icons/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/icons/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/icons/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/icons/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/icons/favicon-194x194.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/icons/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/icons/mstile-144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/icons/mstile-150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/icons/mstile-310x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/icons/mstile-310x310.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/icons/mstile-70x70.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file removed content/mstile-150x150.png
Binary file not shown.
7 changes: 4 additions & 3 deletions content/manifest.json → content/site.webmanifest
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "EasyRPG",
"name": "EasyRPG.org",
"short_name": "EasyRPG",
"icons": [
{
"src": "/android-chrome-192x192.png",
"src": "/images/icons/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/android-chrome-512x512.png",
"src": "/images/icons/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
Expand Down
1 change: 0 additions & 1 deletion content/sitemap.xml

This file was deleted.

7 changes: 1 addition & 6 deletions layouts/default.slim
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ html lang="en"
meta name="description" content="Free and open source role playing game interpreter and editor compatible with RPG Maker 2000 and 2003"
meta name="viewport" content="width=device-width"
meta http-equiv="X-UA-Compatible" content="IE=edge"
link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"
link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"
link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"
link rel="manifest" href="/manifest.json"
link rel="mask-icon" href="/safari-pinned-tab.svg" color="#2d631d"
meta name="theme-color" content="#2d631d"
== render '/icons.*'
link rel="stylesheet" href="#{@items['/css/*'].path}"
script src="/js/vendor/jquery-2.2.4.min.js"
body
Expand Down
17 changes: 17 additions & 0 deletions layouts/icons.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/ apple
link rel="apple-touch-icon" sizes="180x180" href="/images/icons/apple-touch-icon.png"
link rel="mask-icon" href="/images/icons/safari-pinned-tab.svg" color="#5bbad5"
/ standard compliant
link rel="icon" type="image/png" sizes="32x32" href="/images/icons/favicon-32x32.png"
link rel="icon" type="image/png" sizes="194x194" href="/images/icons/favicon-194x194.png"
link rel="icon" type="image/png" sizes="192x192" href="/images/icons/android-chrome-192x192.png"
link rel="icon" type="image/png" sizes="16x16" href="/images/icons/favicon-16x16.png"
meta name="theme-color" content="#2d631d"
/ android
link rel="manifest" href="/site.webmanifest"
/ legacy
link rel="shortcut icon" href="/favicon.ico"
/ microsoft
meta name="msapplication-TileColor" content="#2d631d"
meta name="msapplication-TileImage" content="/images/icons/mstile-144x144.png"
meta name="msapplication-config" content="/browserconfig.xml"
9 changes: 9 additions & 0 deletions lib/asset_hash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# use a hash to avoid caching issues

require 'ruby-xxhash'

def asset_hash(item)
sum = XXhash.xxh32(File.read(@item[:filename]), 0xEA51)
return sum.to_s
end
16 changes: 10 additions & 6 deletions lib/sitemap.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@

# generate a sitemap for search engines (http://www.sitemaps.org/)
include Nanoc::Helpers::XMLSitemap
use_helper Nanoc::Helpers::XMLSitemap

def hide_items_from_sitemap
@items.each do |item|
if %w{css scss xml js txt}.include?(item[:extension]) || item.identifier =~ /404/
item[:is_hidden] = true if item[:is_hidden].nil?
end
# Return all "content" items (pages that are not hidden) for inclusion
def content_items
@items.select do |item|
!item[:is_hidden] && (item[:extension] == '.html' || item.path.to_s.end_with?('/'))
end
end

# called by preprocess block
def write_sitemap_file
@items.create("<%= xml_sitemap(items: content_items) %>", {}, '/sitemap.xml')
end

0 comments on commit fe88369

Please sign in to comment.