在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ HTML/ 輔助函數(shù)(Helpers)
配置
本地化(i18n)
建站
輔助函數(shù)(Helpers)
主題
服務(wù)器
指令
數(shù)據(jù)文件
模版
部署
遷移
標(biāo)簽插件(Tag Plugins)
Front-matter
生成文件
貢獻(xiàn)
問題解答
變量 | Hexo
資源文件夾
插件
寫作
永久鏈接(Permalinks)

輔助函數(shù)(Helpers)

輔助函數(shù)幫助您在模版中快速插入內(nèi)容。

網(wǎng)址

url_for

在路徑前加上根路徑,從 Hexo 2.7 開始您應(yīng)該使用此函數(shù),避免使用 config.root + path

<%- url_for(path) %>

relative_url

取得與 from 相對的 to 路徑。

    <%- relative_url(from, to) %>  

gravatar

插入 Gravatar 圖片。

    <%- gravatar(email, [size]);  

示例:

<%- gravatar('a@abc.com') %>
// http://www.gravatar.com/avatar/b9b00e66c6b8a70f88c73cb6bdb06787

<%- gravatar('a@abc.com', 40) %>
// http://www.gravatar.com/avatar/b9b00e66c6b8a70f88c73cb6bdb06787?s=40

HTML 標(biāo)簽

css

載入 CSS 文件。path 可以是數(shù)組或字符串,如果 path 開頭不是 / 或任何協(xié)議,則會自動加上根路徑;如果后面沒有加上 .css 擴(kuò)展名的話,也會自動加上。

<%- css(path, ...) %>

示例:

<%- css('style.css') %>
// <link rel="stylesheet" href="/style.css" type="text/css">

<%- css(['style.css', 'screen.css']) %>
// <link rel="stylesheet" href="/style.css" type="text/css">
// <link rel="stylesheet" href="/screen.css" type="text/css">

js

載入 JavaScript 文件。path 可以是數(shù)組或字符串,如果 path 開頭不是 / 或任何協(xié)議,則會自動加上根路徑;如果后面沒有加上 .js 擴(kuò)展名的話,也會自動加上。

<%- js(path, ...) %>

示例:

<%- js('script.js') %>
// <script type="text/javascript" src="/script.js"></script>

<%- js(['script.js', 'gallery.js']) %>
// <script type="text/javascript" src="/script.js"></script>
// <script type="text/javascript" src="/gallery.js"></script>

link_to

插入鏈接。

    <%- link_to(path, [text], [options]) %>  
參數(shù) 描述 默認(rèn)值
external 在新視窗打開鏈接 false
class Class 名稱
id ID

示例:

<%- link_to('http://www.google.com') %>
// <a  title="http://www.google.com">http://www.google.com</a>

<%- link_to('http://www.google.com', 'Google') %>
// <a  title="Google">Google</a>

<%- link_to('http://www.google.com', 'Google', {external: true}) %>
// <a  title="Google" target="_blank" rel="external">Google</a>

mail_to

插入電子郵箱鏈接。

    <%- mail_to(path, [text], [options]) %>  
參數(shù) 描述
class Class 名稱
id ID
subject 郵件主題
cc 抄送(CC)
bcc 密送(BCC)
body 郵件內(nèi)容

示例:

<%- mail_to('a@abc.com') %>
// <a href="mailto:a@abc.com" title="a@abc.com">a@abc.com</a>

<%- mail_to('a@abc.com', 'Email') %>
// <a href="mailto:a@abc.com" title="Email">Email</a>

image_tag

插入圖片。

    <%- image_tag(path, [options]) %>  
參數(shù) 描述
alt 圖片的替代文字
class Class 名稱
id ID
width 圖片寬度
height 圖片高度

favicon_tag

插入 favicon。

<%- favicon_tag(path) %>

feed_tag

插入 feed 鏈接。

    <%- feed_tag(path, [options]) %>  
參數(shù) 描述 默認(rèn)值
title Feed 標(biāo)題
type Feed 類型 atom

條件函數(shù)

is_current

檢查 path 是否符合目前頁面的網(wǎng)址。開啟 strict 選項啟用嚴(yán)格比對。

    <%- is_current(path, [strict]) %>  

is_home

檢查目前是否為首頁。

<%- is_home() %>

is_post

檢查目前是否為文章。

<%- is_post() %>

is_archive

檢查目前是否為存檔頁面。

<%- is_archive() %>

is_year

檢查目前是否為年度歸檔頁面。

<%- is_year() %>

is_month

檢查目前是否為月度歸檔頁面。

<%- is_month() %>

is_category

檢查目前是否為分類歸檔頁面。

<%- is_category() %>

is_tag

檢查目前是否為標(biāo)簽歸檔頁面。

<%- is_tag() %>

字符串處理

trim

清除字符串開頭和結(jié)尾的空格。

<%- trim(string) %>

strip_html

清除字符串中的 HTML 標(biāo)簽。

    <%- strip_html(string) %>  

示例:

    <%- strip_html('It's not important anymore!') %>  
    // It's not important anymore!  

titlecase

把字符串轉(zhuǎn)換為正確的 Title case。

<%- titlecase(string) %>

示例:

    <%- titlecase('this is an apple') %>  
    # This is an Apple  

markdown

使用 Markdown 解析字符串。

<%- markdown(str) %>

示例:

<%- markdown('make me **strong**') %>
// make me <strong>strong</strong>

render

解析字符串。

    <%- render(str, engine, [options]) %>  

word_wrap

使每行的字符串長度不超過 lengthlength 預(yù)設(shè)為 80。

    <%- word_wrap(str, [length]) %>  

示例:

<%- word_wrap('Once upon a time', 8) %>
// Once upon\n a time

truncate

移除超過 length 長度的字符串。

    <%- truncate(text, length) %>  

示例:

<%- truncate('Once upon a time in a world far far away', 16) %>
// Once upon a time

模板

partial

載入其他模板文件,您可在 locals 設(shè)定區(qū)域變量。

    <%- partial(layout, [locals], [options]) %>  
參數(shù) 描述 默認(rèn)值
cache 緩存(使用 Fragment cache) false
only 限制局部變量。在模板中只能使用 locals 中設(shè)定的變量。 false

fragment_cache

局部緩存。它儲存局部內(nèi)容,下次使用時就能直接使用緩存。

    <%- fragment_cache(id, fn);  

示例:

    <%- fragment_cache('header', function(){  
      return '';  
    }) %>  

日期與時間

date

插入格式化的日期。date 可以是 UNIX 時間、ISO 字符串、Date 對象或 Moment.js 對象。format 默認(rèn)為 date_format 配置信息。

    <%- date(date, [format]) %>  

示例:

<%- date(Date.now()) %>
// Jan 1, 2013

<%- date(Date.now(), 'YYYY/M/D') %>
// 2013/1/1

date_xml

插入 XML 格式的日期。date 可以是 UNIX 時間、ISO 字符串、Date 對象或 Moment.js 對象。

<%- date_xml(date) %>

示例:

<%- date_xml(Date.now()) %>
// 2013-01-01T00:00:00.000Z

time

插入格式化的時間。date 可以是 UNIX 時間、ISO 字符串、Date 對象或 [Moment.js][1] 對象。format 默認(rèn)為 time_format 配置信息。

    <%- time(date, [format]) %>  

示例:

<%- time(Date.now()) %>
// 13:05:12

<%- time(Date.now(), 'h:mm:ss a') %>
// 1:05:12 pm

full_date

插入格式化的日期和時間。date 可以是 UNIX 時間、ISO 字符串、Date 對象或 Moment.js 對象。format 默認(rèn)為 time_format 配置信息。

    <%- full_date(date, [format]) %>  

示例:

<%- full_date(new Date()) %>
// Jan 1, 2013 0:00:00

<%- full_date(new Date(), 'dddd, MMMM Do YYYY, h:mm:ss a') %>
// Tuesday, January 1st 2013, 12:00:00 am

moment

Moment.js 函數(shù)庫。

列表

list_categories

插入分類列表。

    <%- list_categories([categories], [options]) %>  
參數(shù) 描述 默認(rèn)值
orderby 分類排列方式 name
order 分類排列順序。1, asc 升序;-1, desc 降序。 1
show_count 顯示每個分類的文章總數(shù) true
style 分類列表的顯示方式。使用 list 以無序列表(unordered list)方式顯示。 list
separator 分類間的分隔符號。只有在 style 不是 list 時有用。 ,
depth 要顯示的分類層級。0 顯示所有層級的分類;-10 很類似,但是顯示不分層級;1 只顯示第一層的分類。 0
class 分類列表的 class 名稱。 category
transform 改變分類名稱顯示方法的函數(shù)

list_tags

插入標(biāo)簽列表。

    <%- list_tags([tags], [options]) %>  
選項 描述 預(yù)設(shè)值
orderby 標(biāo)簽排列方式 name
order 標(biāo)簽排列順序。1, asc 升序;-1, desc 降序。 1
show_count 顯示每個標(biāo)簽的文章總數(shù) true
style 標(biāo)簽列表的顯示方式。使用 list 以無序列表(unordered list)方式顯示。 list
separator 標(biāo)簽間的分隔符號。只有在 style 不是 list 時有用。 ,
class 標(biāo)簽列表的 class 名稱。 tag
transform 改變標(biāo)簽名稱顯示方法的函數(shù)
amount 要顯示的標(biāo)簽數(shù)量(0 = 無限制) 0

list_archives

插入歸檔列表。

    <%- list_archives([options]) %>  
參數(shù) 描述 默認(rèn)值
type 類型。此設(shè)定可為 yearlymonthly。 monthly
order 排列順序。1, asc 升序;-1, desc 降序。 1
show_count 顯示每個歸檔的文章總數(shù) true
format 日期格式 MMMM YYYY
style 歸檔列表的顯示方式。使用 list 以無序列表(unordered list)方式顯示。 list
separator 歸檔間的分隔符號。只有在 style 不是 list 時有用。 ,
class 歸檔列表的 class 名稱。 archive
transform 改變歸檔名稱顯示方法的函數(shù)

list_posts

插入文章列表。

    <%- list_posts([options]) %>  
參數(shù) 描述 默認(rèn)值
orderby 文章排列方式 date
order 文章排列順序。1, asc 升序;-1, desc 降序。 -1
style 文章列表的顯示方式。使用 list 以無序列表(unordered list)方式顯示。 list
separator 文章間的分隔符號。只有在 style 不是 list 時有用。 ,
class 文章列表的 class 名稱。 post
amount 要顯示的文章數(shù)量(0 = 無限制) 6
transform 改變文章名稱顯示方法的函數(shù)

tagcloud

插入標(biāo)簽云。

    <%- tagcloud([tags], [options]) %>  
參數(shù) 描述 默認(rèn)值
min_font 最小字體尺寸 10
max_font 最大字體尺寸 20
unit 字體尺寸的單位 px
amount 標(biāo)簽總量 40
orderby 標(biāo)簽排列方式 name
order 標(biāo)簽排列順序。1, sac 升序;-1, desc 降序 1
color 使用顏色 false
start_color 開始的顏色。您可使用十六進(jìn)位值(#b700ff),rgba(rgba(183, 0, 255, 1)),hsla(hsla(283, 100%, 50%, 1))或 [顏色關(guān)鍵字][2]。此變量僅在 color 參數(shù)開啟時才有用。
end_color 結(jié)束的顏色。您可使用十六進(jìn)位值(#b700ff),rgba(rgba(183, 0, 255, 1)),hsla(hsla(283, 100%, 50%, 1))或 [顏色關(guān)鍵字][2]。此變量僅在 color 參數(shù)開啟時才有用。

其他

paginator

插入分頁鏈接。

    <%- paginator(options) %>  
參數(shù) 描述 默認(rèn)值
base 基礎(chǔ)網(wǎng)址 /
format 網(wǎng)址格式 page/%d/
total 分頁總數(shù) 1
current 目前頁數(shù) 0
prev_text 上一頁鏈接的文字。僅在 prev_next 設(shè)定開啟時才有用。 Prev
next_text 下一頁鏈接的文字。僅在 prev_next 設(shè)定開啟時才有用。 Next
space 空白文字 &hellp;
prev_next 顯示上一頁和下一頁的鏈接 true
end_size 顯示于兩側(cè)的頁數(shù) 1
mid_size 顯示于中間的頁數(shù) 2
show_all 顯示所有頁數(shù)。如果開啟此參數(shù)的話,end_sizemid_size 就沒用了。 false

search_form

插入 Google 搜索框。

    <%- search_form(options) %>  
參數(shù) 描述 默認(rèn)值
class 表單的 class name search-form
text 搜索提示文字 Search
button 顯示搜索按鈕。此參數(shù)可為布爾值(boolean)或字符串,當(dāng)設(shè)定是字符串的時候,即為搜索按鈕的文字。 false

number_format

格式化數(shù)字。

    <%- number_format(number, [options]) %>  
參數(shù) 描述 默認(rèn)值
precision 數(shù)字精度。此選項可為 false 或非負(fù)整數(shù)。 false
delimiter 千位數(shù)分隔符號 ,
separator 整數(shù)和小數(shù)之間的分隔符號 .

示例:

<%- number_format(12345.67, {precision: 1}) %>
// 12,345.68

<%- number_format(12345.67, {precision: 4}) %>
// 12,345.6700

<%- number_format(12345.67, {precision: 0}) %>
// 12,345

<%- number_format(12345.67, {delimiter: ''}) %>
// 12345.67

<%- number_format(12345.67, {separator: '/'}) %>
// 12,345/67

open_graph

插入 open graph 資源。

    <%- open_graph([options]) %>  
參數(shù) 描述 默認(rèn)值
title 頁面標(biāo)題 (og:title) page.title
type 頁面類型 (og:type) blog
url 頁面網(wǎng)址 (og:url) url
image 頁面圖片 (og:image) 內(nèi)容中的圖片
site_name 網(wǎng)站名稱 (og:site_name) config.title
description 頁面描述 (og:desription) 內(nèi)容摘要或前 200 字
twitter_card Twitter 卡片類型 (twitter:card) summary
twitter_id Twitter ID (twitter:creator)
twitter_site Twitter 網(wǎng)站 (twitter:site)
google_plus Google+ 個人資料鏈接
fb_admins Facebook 管理者 ID
fb_app_id Facebook 應(yīng)用程序 ID

toc

解析內(nèi)容中的標(biāo)題標(biāo)簽 (h1~h6) 并插入目錄。

    <%- toc(str, [options]) %>  
參數(shù) 描述 默認(rèn)值
class Class 名稱 toc
list_number 顯示編號 true

示例:

<%- toc(page.content) %>
上一篇:資源文件夾下一篇:模版