Method: JekyllAdmin::APIable#to_api
- Defined in:
- lib/jekyll-admin/apiable.rb
#to_api(include_content: false) ⇒ Object
Returns a hash suitable for use as an API response.
For Documents and Pages:
-
Adds the file’s raw content to the
raw_contentfield -
Adds the file’s raw YAML front matter to the
front_matterfield
For Static Files it addes the Base64 encoded_content field
Options:
include_content - if true, includes the content in the respond, false by default
to support mapping on indexes where we only want
Returns a hash (which can then be to_json’d)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/jekyll-admin/apiable.rb', line 25 def to_api(include_content: false) output = API_SCAFFOLD.merge hash_for_api # Include content, if requested, otherwise remove it if include_content output.merge!(content_fields) else CONTENT_FIELDS.each { |field| output.delete(field) } end # Documents have duplicate output and content fields, Pages do not # Since it's an API, use `content` in both for consistency output.delete("output") output["name"] = basename if is_a?(Jekyll::Document) output["from_theme"] = from_theme_gem? if is_a?(Jekyll::StaticFile) output["relative_path"] = relative_path_for_api # By default, calling to_liquid on a collection will return a docs # array with each rendered document, which we don't want. if is_a?(Jekyll::Collection) output.delete("docs") output["name"] = label output["path"] = relative_directory output["entries_url"] = entries_url end output.merge!(url_fields) output end |