Sha256: bbdd697b55fd19d8587d5f1c500c783d046a2f7f8fa70d3699cddd37cd91e71c

Contents?: true

Size: 749 Bytes

Versions: 14

Compression:

Stored size: 749 Bytes

Contents

# frozen_string_literal: true

module Bridgetown
  class Publisher
    # @param site [Bridgetown::Site]
    def initialize(site)
      @site = site
    end

    def publish?(thing)
      can_be_published?(thing) && !hidden_in_the_future?(thing)
    end

    def hidden_in_the_future?(thing)
      return false unless thing.respond_to?(:date)

      future_allowed =
        (thing.respond_to?(:collection) && thing.collection.metadata.future) || @site.config.future
      thing_time = thing.date.is_a?(Date) ? thing.date.to_time.to_i : thing.date.to_i
      !future_allowed && thing_time > @site.time.to_i
    end

    private

    def can_be_published?(thing)
      thing.data.fetch("published", true) || @site.config.unpublished
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
bridgetown-core-1.0.0 lib/bridgetown-core/publisher.rb
bridgetown-core-1.0.0.beta3 lib/bridgetown-core/publisher.rb
bridgetown-core-1.0.0.beta2 lib/bridgetown-core/publisher.rb
bridgetown-core-1.0.0.beta1 lib/bridgetown-core/publisher.rb
bridgetown-core-1.0.0.alpha11 lib/bridgetown-core/publisher.rb
bridgetown-core-1.0.0.alpha10 lib/bridgetown-core/publisher.rb
bridgetown-core-1.0.0.alpha9 lib/bridgetown-core/publisher.rb
bridgetown-core-1.0.0.alpha8 lib/bridgetown-core/publisher.rb
bridgetown-core-1.0.0.alpha7 lib/bridgetown-core/publisher.rb
bridgetown-core-1.0.0.alpha6 lib/bridgetown-core/publisher.rb
bridgetown-core-1.0.0.alpha5 lib/bridgetown-core/publisher.rb
bridgetown-core-1.0.0.alpha4 lib/bridgetown-core/publisher.rb
bridgetown-core-1.0.0.alpha3 lib/bridgetown-core/publisher.rb
bridgetown-core-1.0.0.alpha2 lib/bridgetown-core/publisher.rb