Skip to content

Commit

Permalink
Getting ready for 0.9 release (see changelog) (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite authored Apr 16, 2020
1 parent 37b2fcd commit 5972299
Show file tree
Hide file tree
Showing 43 changed files with 382 additions and 221 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# master

* Update table styling in Documentation
* Now showing the plugins_dir in log output if it's present
* With the Posts Reader changes, now you can add a Front Matter Default of
`_posts/drafts` having `published: false`, put a bunch of draft posts in
`_posts/drafts` and you're done!
* New `-U` flag makes it easier to specify generating `published: false` docs.
* The Posts Reader has been reworked so that files with valid front matter can
be read in even if there's no YYYY-MM-DD- at the beginning. In addition, static
files are also supported, which means if you can create a folder (`inlinefiles`),
drop a post in along with a bunch of images, and use `![alt](some-image.jpg)`
relative paths, it'll work! Big improvement to Markdown authoring. (You'll need
to use a permalink in a specific manner though, e.g.
`permalink: /inlinefiles/:title:output_ext`)
If you need a static file not to get copied to the destination, just add an
`_` at the beginning and it'll get ignored.
* Collections no longer allow displaying a full server file path via Liquid.
* `{{ page.collection }}` now returns a CollectionDrop, not the label of
the collection. Using the `jsonify` filter on a document however still returns
just the label for the `collection` key.
* Add favicon to website
* Add mobile improvements to website
* Add back working feature tests for basic pagination
Expand Down
16 changes: 11 additions & 5 deletions bridgetown-core/lib/bridgetown-core/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,20 @@ def relative_directory
@relative_directory ||= "_#{label}"
end

# The relative path to the directory containing the collection.
#
# Returns a String containing the directory name where the collection
# is stored relative to the source directory
def relative_path
Pathname.new(container).join(relative_directory).to_s
end

# The full path to the directory containing the collection.
#
# Returns a String containing th directory name where the collection
# Returns a String containing the directory name where the collection
# is stored on the filesystem.
def directory
@directory ||= site.in_source_dir(
File.join(container, relative_directory)
)
@directory ||= site.in_source_dir(relative_path)
end

# The full path to the directory containing the collection, with
Expand Down Expand Up @@ -263,7 +269,7 @@ def order_with_warning(sort_key, document, order)

def read_static_file(file_path, full_path)
relative_dir = Bridgetown.sanitized_path(
relative_directory,
relative_path,
File.dirname(file_path)
).chomp("/.")

Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/lib/bridgetown-core/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def add_build_options(cmd)
"Serve the website from the given base URL"
cmd.option "force_polling", "--force_polling", "Force watch to use polling"
cmd.option "lsi", "--lsi", "Use LSI for improved related posts"
cmd.option "unpublished", "--unpublished",
cmd.option "unpublished", "-U", "--unpublished",
"Render posts that were marked as unpublished"
cmd.option "disable_disk_cache", "--disable-disk-cache",
"Disable caching to disk"
Expand Down
43 changes: 28 additions & 15 deletions bridgetown-core/lib/bridgetown-core/commands/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,52 +30,51 @@ def process(options)
" build is about to begin…"

options = configuration_from_options(options)
site = Bridgetown::Site.new(options)
@site = Bridgetown::Site.new(options)

if options.fetch("skip_initial_build", false)
Bridgetown.logger.warn "Build Warning:", "Skipping the initial build." \
" This may result in an out-of-date site."
else
build(site, options)
build(options)
end

if options.fetch("detach", false)
Bridgetown.logger.info "Auto-regeneration:",
"disabled when running server detached."
elsif options.fetch("watch", false)
watch(site, options)
watch(options)
else
Bridgetown.logger.info "Auto-regeneration:", "disabled. Use --watch to enable."
end
end

# Build your Bridgetown site.
#
# site - the Bridgetown::Site instance to build
# options - A Hash of options passed to the command
# options - A Hash of options passed to the command or loaded from config
#
# Returns nothing.
def build(site, options)
def build(options)
t = Time.now
source = File.expand_path(options["source"])
destination = File.expand_path(options["destination"])
display_folder_paths(options)
if options["unpublished"]
Bridgetown.logger.info "Unpublished mode:",
"enabled. Processing documents marked unpublished"
end
incremental = options["incremental"]
Bridgetown.logger.info "Source:", source
Bridgetown.logger.info "Destination:", destination
Bridgetown.logger.info "Incremental build:",
(incremental ? "enabled" : "disabled. Enable with --incremental")
Bridgetown.logger.info "Generating…"
process_site(site)
process_site(@site)
Bridgetown.logger.info "Done! 🎉", "Completed in #{(Time.now - t).round(3)} seconds."
end

# Private: Watch for file changes and rebuild the site.
#
# site - A Bridgetown::Site instance
# options - A Hash of options passed to the command
# options - A Hash of options passed to the command or loaded from config
#
# Returns nothing.
def watch(site, options)
def watch(options)
# Warn Windows users that they might need to upgrade.
if Utils::Platforms.bash_on_windows?
Bridgetown.logger.warn "",
Expand All @@ -88,7 +87,21 @@ def watch(site, options)
end

# External.require_with_graceful_fail "bridgetown-watch"
Bridgetown::Watcher.watch(options, site)
Bridgetown::Watcher.watch(@site, options)
end

# Private: display the source and destination folder paths
#
# options - A Hash of options passed to the command
#
# Returns nothing.
def display_folder_paths(options)
source = File.expand_path(options["source"])
destination = File.expand_path(options["destination"])
plugins_dir = File.expand_path(options["plugins_dir"])
Bridgetown.logger.info "Source:", source
Bridgetown.logger.info "Destination:", destination
Bridgetown.logger.info "Custom Plugins:", plugins_dir if Dir.exist?(plugins_dir)
end
end
end
Expand Down
9 changes: 1 addition & 8 deletions bridgetown-core/lib/bridgetown-core/commands/serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def init_with_program(prog)
opts["serving"] = true
opts["watch"] = true unless opts.key?("watch")

# TODO: this prints the configuration file log message out-of-order
config = configuration_from_options(opts)
config["url"] = default_url(config) if Bridgetown.env == "development"

Expand Down Expand Up @@ -121,8 +122,6 @@ def webrick_opts(opts)
end

def start_up_webrick(opts, destination)
@reload_reactor.start(opts) if opts["livereload"]

@server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }
@server.mount(opts["baseurl"].to_s, Servlet, destination, file_handler_opts)

Expand Down Expand Up @@ -234,8 +233,6 @@ def start_callback(detached)
unless detached
proc do
mutex.synchronize do
# Block until EventMachine reactor starts
@reload_reactor&.started_event&.wait
@running = true
Bridgetown.logger.info("Server running…", "press ctrl-c to stop.")
@run_cond.broadcast
Expand All @@ -248,10 +245,6 @@ def stop_callback(detached)
unless detached
proc do
mutex.synchronize do
unless @reload_reactor.nil?
@reload_reactor.stop
@reload_reactor.stopped_event.wait
end
@running = false
@run_cond.broadcast
end
Expand Down
4 changes: 2 additions & 2 deletions bridgetown-core/lib/bridgetown-core/drops/collection_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class CollectionDrop < Drop
mutable false

def_delegator :@obj, :write?, :output
def_delegators :@obj, :label, :docs, :files, :directory, :relative_directory
def_delegators :@obj, :label, :docs, :files, :relative_path

private def_delegator :@obj, :metadata, :fallback_data

def to_s
docs.to_s
label
end
end
end
Expand Down
9 changes: 6 additions & 3 deletions bridgetown-core/lib/bridgetown-core/drops/document_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DocumentDrop < Drop
private def_delegator :@obj, :data, :fallback_data

def collection
@obj.collection.label
@collection ||= @obj.collection.to_liquid
end

def excerpt
Expand All @@ -33,11 +33,11 @@ def <=>(other)
end

def previous
@obj.previous_doc.to_liquid
@previous ||= @obj.previous_doc.to_liquid
end

def next
@obj.next_doc.to_liquid
@next ||= @obj.next_doc.to_liquid
end

# Generate a Hash for use in generating JSON.
Expand All @@ -48,6 +48,9 @@ def next
# Returns a Hash ready for JSON generation.
def hash_for_json(state = nil)
to_h.tap do |hash|
# use collection label in the hash
hash["collection"] = hash["collection"]["label"] if hash["collection"]

if state && state.depth >= 2
hash["previous"] = collapse_document(hash["previous"]) if hash["previous"]
hash["next"] = collapse_document(hash["next"]) if hash["next"]
Expand Down
5 changes: 4 additions & 1 deletion bridgetown-core/lib/bridgetown-core/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ def read_directories(dir = "")
def retrieve_posts(dir)
return if outside_configured_directory?(dir)

site.posts.docs.concat(post_reader.read_posts(dir))
post_reader.read_posts(dir).tap do |entries|
site.posts.docs.concat(entries.select { |entry| entry.is_a?(Document) })
site.posts.files.concat(entries.select { |entry| entry.is_a?(StaticFile) })
end
end

# Recursively traverse directories with the read_directories function.
Expand Down
34 changes: 27 additions & 7 deletions bridgetown-core/lib/bridgetown-core/readers/post_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def read_posts(dir)
# Returns nothing.
def read_publishable(dir, magic_dir, matcher)
read_content(dir, magic_dir, matcher)
.tap { |docs| docs.each(&:read) }
.select { |doc| processable?(doc) }
.tap { |entries| entries.select { |entry| entry.respond_to?(:read) }.each(&:read) }
.select { |entry| processable?(entry) }
end

# Read all the content files from <source>/<dir>/magic_dir
Expand All @@ -40,18 +40,38 @@ def read_publishable(dir, magic_dir, matcher)
# Returns klass type of content files
def read_content(dir, magic_dir, matcher)
@site.reader.get_entries(dir, magic_dir).map do |entry|
next unless matcher.match?(entry)

path = @site.in_source_dir(File.join(dir, magic_dir, entry))
Document.new(path,
site: @site,
collection: @site.posts)

if matcher.match?(entry) || Utils.has_yaml_header?(path)
# Process as Document
Document.new(path,
site: @site,
collection: @site.posts)
else
# Process as Static File
read_static_file(
path,
File.join(dir, magic_dir, File.dirname(entry).sub(".", ""))
)
end
end.reject(&:nil?)
end

private

def read_static_file(full_path, relative_dir)
StaticFile.new(
site,
site.source,
relative_dir,
File.basename(full_path),
@site.posts
)
end

def processable?(doc)
return true if doc.is_a?(StaticFile)

if doc.content.nil?
Bridgetown.logger.debug "Skipping:", "Content in #{doc.relative_path} is nil"
false
Expand Down
11 changes: 3 additions & 8 deletions bridgetown-core/lib/bridgetown-core/static_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ def initialize(site, base, dir, name, collection = nil)
# Returns source file path.
def path
@path ||= begin
# Static file is from a collection inside custom collections directory
if !@collection.nil? && !@site.config["collections_dir"].empty?
File.join(*[@base, @site.config["collections_dir"], @dir, @name].compact)
else
File.join(*[@base, @dir, @name].compact)
end
File.join(*[@base, @dir, @name].compact)
end
end

Expand Down Expand Up @@ -149,7 +144,7 @@ def cleaned_relative_path
@cleaned_relative_path ||= begin
cleaned = relative_path[0..-extname.length - 1]
cleaned.gsub!(%r!\.*\z!, "")
cleaned.sub!(@collection.relative_directory, "") if @collection
cleaned.sub!(@collection.relative_path, "") if @collection
cleaned
end
end
Expand All @@ -159,7 +154,7 @@ def cleaned_relative_path
# be overriden in the collection's configuration in bridgetown.config.yml.
def url
@url ||= begin
base = if @collection.nil?
base = if @collection.nil? || @collection.label == "posts"
cleaned_relative_path
else
Bridgetown::URL.new(
Expand Down
12 changes: 3 additions & 9 deletions bridgetown-core/lib/bridgetown-core/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,17 @@ module Watcher
# Public: Continuously watch for file changes and rebuild the site
# whenever a change is detected.
#
# If the optional site argument is populated, that site instance will be
# reused and the options Hash ignored. Otherwise, a new site instance will
# be instantiated from the options Hash and used.
#
# site - The current site instance
# options - A Hash containing the site configuration
# site - The current site instance (populated starting with Bridgetown 3.2)
# (optional, default: nil)
#
# Returns nothing.
def watch(options, site = nil)
def watch(site, options)
ENV["LISTEN_GEM_DEBUGGING"] ||= "1" if options["verbose"]

site ||= Bridgetown::Site.new(options)
listener = build_listener(site, options)
listener.start

Bridgetown.logger.info "Auto-regeneration:", "enabled for '#{options["source"]}'"
Bridgetown.logger.info "Auto-regeneration:", "enabled."

unless options["serving"]
trap("INT") do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: What Am I?
date: 2009-03-05
---

I am not a post.
Am I a document then..?
I am not a "standard" post, but I'll be processed because
the front matter is present.
8 changes: 2 additions & 6 deletions bridgetown-core/test/test_collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ class TestCollections < BridgetownUnitTest
assert_equal [], @collection.to_liquid["files"]
end

should "have a directory attribute" do
assert_equal @collection.to_liquid["directory"], source_dir("_methods")
end

should "have a relative_directory attribute" do
assert_equal "_methods", @collection.to_liquid["relative_directory"]
should "have a relative_path attribute" do
assert_equal "_methods", @collection.to_liquid["relative_path"]
end

should "have a output attribute" do
Expand Down
Loading

0 comments on commit 5972299

Please sign in to comment.