Jekyll 使用Liquid来处理模板数据。在建立中文博客的过程中,常常会苦于无法在文章中显示中文或阿拉伯数字形式日期的问题,而网上绝大多数给出的方案都只是官方的文档给出的 07 Jan 2015。为了能够了解Jekyll模板中不同对象究竟有哪些可以使用的方法,写下此文。
在Liquid中,以上面的语句为例,page为object对象,page.date为attribute属性,后面的date_to_string叫做filter过滤器。请参考Liquid官网关于Objects的介绍。而在Jekyll中page被叫做Global Variables全局变量,而每个全局变量拥有的多个属性被称为子变量,如Site全局变量的子变量为Site Variables。 请参考官网的变量介绍一页。
不同的属性拥有不同的类型,有的属于数组,有的属于字符,有的属于日期时间等等,下面分别介绍不同类型属性的过滤器:
#数组过滤器
主要包括以下对象:
- site.pages
- site.posts
- site.related_posts
- site.static_files
- site.html_pages
- site.collections
- site.data
- site.documents
- site.categories
- site.categories.CATEGORY
- site.tags
- site.tags.TAG
- site.[CONFIGURATION_DATA]
- page.categories
- page.tags
- paginator.posts
###join
=>
###first
=>
###last
=>
###map
=>
###size
=>
###sort
=>
#HTML标签过滤器
###img_tag
=>
###script_tag
=>
###stylesheet_tag
=>
#数学函数过滤器
主要包括以下对象:
- paginator.per_page
- paginator.total_posts
- paginator.total_pages
- paginator.page
- paginator.previous_page
- paginator.previous_page_path
- paginator.next_page
- paginator.next_page_path
###ceil
=>
###divided_by
=>
###floor
=>
###minus
=>
###plus
=>
###round
=>
###times
=>
###modulo
=>
#货币函数过滤器
###money
=>
###money_with_currency
=>
###money_without_currency
=>
#字符串过滤器
主要包括以下对象:
- page.content
- page.title
- page.excerpt
- page.url
- page.id
- page.path
###append
=>
###camelcase
=>
###capitalize
=>
###downcase
=>
###escape
=>
###handle/handleize
=>
###md5
=>
###newline_to_br
=>
###pluralize
=>
###prepend
=>
###remove
=>
###remove_first
=>
###replace
=>
###replace_first
=>
###slice
=>
=>
###split
=>
###strip
=>
###lstrip
=>
###rstrip
=>
###strip_html
=>
###strip_newlines
###truncate
=>
###truncatewords
=>
###uniq
=>
###upcase
=>
###url_escape
=>
###url_param_escape
=>
###number_of_words
=>
###array_to_sentence_string
=>
#日期过滤器
主要包括以下对象:
=>
###%a:Abbreviated weekday.
=>
###%A:Full weekday name.
=>
###%b:Abbreviated month name.
=>
###%B:Full month name
=>
###%c:Preferred local date and time representation
=>
###%d:Day of the month, zero-padded (01, 02, 03, etc.).
=>
###%-d:Day of the month, not zero-padded (1,2,3, etc.).
=>
###%D:Formats the date (dd/mm/yy).
=>
###%e:Day of the month, blank-padded ( 1, 2, 3, etc.).
=>
###%F:Returns the date in ISO 8601 format (yyyy-mm-dd).
=>
###%H:Hour of the day, 24-hour clock (00 - 23).
=>
###%I:Hour of the day, 12-hour clock (1 - 12).
=>
###%j:Day of the year (001 - 366).
=>
###%k:Hour of the day, 24-hour clock (1 - 24).
=>
###%m:Month of the year (01 - 12).
=>
###%M:Minute of the hour (00 - 59).
=>
###%p:Meridian indicator (AM/PM).
=>
###%r:12-hour time (%I:%M:%S %p)
=>
###%R:24-hour time (%H:%M)
=>
###%T:24-hour time (%H:%M:%S)
=>
###%U:The number of the week in the current year, starting with the first Sunday as the first day of the first week.
=>
###%W:The number of the week in the current year, starting with the first Monday as the first day of the first week.
=>
###%w:Day of the week (0 - 6, with Sunday being 0).
=>
###%x:Preferred representation for the date alone, no time. (mm/dd/yy).
=>
###%X:Preferred representation for the time. (hh:mm:ss).
=>
###%y:Year without a century (00.99).
=>
###%Y:Year with a century.
=>
###%Z:Time zone name.
=>
###date_to_xmlschema
=>
###date_to_string
=>
###date_to_long_string
=>
#其他过滤器
###default
=>
###default_errors
=>
###default_pagination
=>
###highlight
=>
###highlight_active_tag
=>
###json
=>
###weight_with_unit
=>