class StaticdUtils::Sitemap
Manifest for Staticd
releases.
A Sitemap
consist of an associative array representing each resources of a site release. Each entry consist of the sha1 digest of the resource content and the complete HTTP path this resource must be available to.
Example:
sitemap = StaticdUtils::Sitemap.create("/tmp/my_website") sitemap.to_h # => { "058ec3fa8aab4c0ccac27d80fd24f30a8730d3f6"=>"/index.html", "92136ff551f50188f46486ab80db269eda4dfd4e"=>"/hello/world.html" }
Public Class Methods
Create a sitemap from a directory content.
It register each files digest and path inside the sitemap.
# File lib/staticd_utils/sitemap.rb, line 25 def self.create(path) map = {} if File.directory?(path) Dir.chdir(path) do Dir["**/*"].each do |object| if File.file?(object) sha1 = Digest::SHA1.hexdigest(File.read(object)) map[sha1] = "/#{object}" end end end end new(map) end
Create a sitemap from an associative array.
The associative array must have the folowing structure:
-
Key: the sha1 of the ressource
-
Value: the HTTP path of the resource
Example:
sitemap = Sitemap.new({ 058ec3fa8aab4c0ccac27d80fd24f30a8730d3f6: "hi.html" })
# File lib/staticd_utils/sitemap.rb, line 68 def initialize(map) @map = map end
Create a sitemap from a YAML string.
The YAML string must reflect the sitemap associative array structure.
Example:
yaml = "---\n058ec3fa8aab4c0ccac27d80fd24f30a8730d3f6: \"/hi.html\"\n" sitemap = StaticdUtils::Sitemap.open(yaml)
# File lib/staticd_utils/sitemap.rb, line 47 def self.open(yaml) new(YAML.load(yaml)) end
Create a sitemap from a YAML file.
The YAML file must reflect the sitemap associative array structure.
# File lib/staticd_utils/sitemap.rb, line 54 def self.open_file(path) open(File.read(path)) end
Public Instance Methods
View all sha1 digest of the sitemap.
# File lib/staticd_utils/sitemap.rb, line 78 def digests @map.map { |sha1, path| sha1 } end
Iterate over each resources of the sitemap.
# File lib/staticd_utils/sitemap.rb, line 83 def each_resources @map.each { |sha1, path| yield sha1, path } end
View all HTTP path of the sitemap.
# File lib/staticd_utils/sitemap.rb, line 73 def routes @map.map { |sha1, path| path } end
# File lib/staticd_utils/sitemap.rb, line 87 def to_h @map end
Export the sitemap to a YAML file stored into memory.
# File lib/staticd_utils/sitemap.rb, line 96 def to_memory_file StaticdUtils::MemoryFile.new(StringIO.new(to_yaml)) end
# File lib/staticd_utils/sitemap.rb, line 91 def to_yaml @map.to_yaml end