-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: jekyll-offline works again, no issue with URI:Module and the cod…
…e is simplified
- Loading branch information
Showing
8 changed files
with
161 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
demo_offline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,5 @@ | ||
# Default configuration for offline jekyll site generation | ||
|
||
:absolute_base: "https://address.of.site.com/" # The full URL of the site as it might appear in any absolute links on the website. (these will be converted to relative links) | ||
:relative_base: "/blog" # Optional - use this if the original site is located in a subdirectory | ||
:source_dir: "~/Downloads/spiffy_website/_site/" # This should point to the _site folder of the generated Jekyll website | ||
:out_dir: "~/my_website_offline/" # The desired output directory where you would like to generate the offline version of the site | ||
# :custom_filter: "fn:|fnref:" # Optional: specify a custom string to filter -- URLS containing this string will not be rewritten | ||
|
||
# boilerplate variables | ||
:site_title: "My Website Title" | ||
:site_url: "https://address.of.site.com/" # URL of the original site | ||
:site_logo: "" # Image to use for site logo on intro page | ||
:source: "~/workspace/root/_site" # This should point to the _site folder of the generated Jekyll website | ||
:target: "~/Downloads" # The desired output directory where you would like to generate the offline version of the site | ||
:site_url: "http://localhost:4000" # URL of the original site (http://localhost:4000/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
# Demo configuration for offline jekyll site | ||
|
||
:absolute_base: "https://address.of.site.com/" | ||
:relative_base: "/demo" | ||
:source_dir: "demo/_site/" | ||
:out_dir: "demo_offline/" | ||
|
||
# boilerplate variables | ||
:site_title: "Demo Site" | ||
:site_url: "https://dohliam.github.io/offline-jekyll/" | ||
:site_logo: "" | ||
:source: "demo/_site/" | ||
:target: "" | ||
:site_url: "http://yourdomain.com/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Converts a html file to a offline html file | ||
# Input : | ||
# - page_path: html file path | ||
# - main_folder_path: (kinda useless, but now we have the page relative path) | ||
# - site_url: remove this from every link | ||
# Output : | ||
# - page_content, hopefully our html file adapted for local use | ||
require 'pathname' | ||
|
||
def convert_to_offline(page_path, main_folder_path, site_url) # Flemme d'améliorer la signature, déso | ||
page_relative_path = page_path.gsub(/^#{main_folder_path}/, "") # Path relative to the working directory | ||
|
||
page_content = File.read(page_path) | ||
|
||
page_content = page_content.gsub(/(href|src)=["'](.*?)["']/) do |link| | ||
href = $1 | ||
address = $2 | ||
|
||
unless is_custom_filter?() || (is_url?(address) && !address.start_with?(site_url)) | ||
# add index.html to folder links that end with "/" | ||
address += "index.html" if address.end_with?("/") | ||
|
||
# add /index.html to folder links that end like "/something" with no extension | ||
address += "/index.html" unless has_extension?(address) | ||
|
||
# remove the site_url from paths | ||
address.sub!(/^#{Regexp.escape(site_url)}/, "") | ||
|
||
# remove the multiple "/" | ||
address.gsub!(/\/+/, '/') | ||
|
||
# create the relative path from the page to the link address | ||
address = construct_relative_path(page_relative_path, "/") + address | ||
|
||
# remove the first "/" | ||
address = address.sub(/^\//, ""); | ||
end | ||
href + "=" + "'#{address}'" | ||
end | ||
page_content | ||
end | ||
|
||
def is_custom_filter?() | ||
@config[:custom_filter] && href.match(/#{@config[:custom_filter]}/) | ||
end | ||
|
||
def is_url?(address) | ||
# Check if the address starts with common web references | ||
return true if address.match?(/\A(http|https|ftp|mailto)/) | ||
false | ||
end | ||
|
||
|
||
def has_extension?(file_path) | ||
!File.extname(file_path).empty? | ||
end | ||
|
||
def construct_relative_path(from_address, to_address) | ||
from_path = Pathname.new(from_address) | ||
to_path = Pathname.new(to_address) | ||
|
||
relative_path = to_path.relative_path_from(from_path.dirname).to_s | ||
|
||
# Adjust the relative path to include "../" if necessary | ||
relative_path.empty? ? '.' : relative_path | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.