2014-03-03 19 views
2

在Wintersmith中,默認博客模板生成來自內容/文章/ <文章> /index.md的文章。這很好,因爲它允許像文件一樣包含圖像等相關文件。但實際上,大多數「博客文章」只是與模板相關的文本內容。不得不創建子目錄是一個小問題,如果在標籤編輯器中編輯多個條目,那麼討厭擁有名爲index.md的所有內容。我如何在Wintersmith中找到不在自己的子目錄中的文章?

網站生成器將會吐出文章/ basic-post.html文件,但不會在生成的索引或存檔頁面中包含這些文件。我怎樣才能讓後者在沒有破壞的情況下工作?

這可能也可能不是一個簡單的問題,但我是Wintersmith的新手,並沒有看到如何做到這一點。我不知道這是因爲編輯默認分頁程序爲瑣碎的(我不是說用的CoffeeScript,這也許是時候來解決:)

在paginator.coffee:

getArticles = (contents) -> 
    # helper that returns a list of articles found in *contents* 
    # note that each article is assumed to have its own directory in the articles directory 
    articles = contents[options.articles]._.directories.map (item) -> item.index 
    articles.sort (a, b) -> b.date - a.date 
    return articles 

這看起來就像這個地方一樣,但是直接編輯一個插件似乎是一個糟糕的主意,因爲未來的更新可能會起作用。

Wintersmith是相當真棒順便說一句。

+0

對不起,但我不完全明白你想要做什麼。是關於將渲染模板與給定文章內容關聯的嗎?還是關於內容目錄組織? – Feugy

+0

我喜歡能夠將content/articles/foo/index.md以及content/articles/bar.md都放到輸出中(它可以直接使用)並且有主要列表(索引和歸檔)頁面包含這些生成的文件(這不起作用)。這是否澄清了這個問題? –

回答

3

你說得對:這個插件是paginator的插件。

Wintersmith將會持續觀看contents文件夾,建立一個ContentTree陣列。 該objet數組將包含contents中每個文件和文件夾的描述符。

getArticles只是過濾這個可能的候選人,你只需要加強它以獲得contents/articles文件夾中的普通降價文件。

getArticles = (contents) -> 
    # helper that returns a list of articles found in *contents* 
    # include articles with dedicated directory 
    articles = contents[options.articles]._.directories.map (item) -> item.index 
    # add articles that are in the *contents/articles* folder 
    articles = articles.concat contents[options.articles]._.pages 
    articles.sort (a, b) -> b.date - a.date 
    return articles 
+0

不錯!我非常接近,擁有完全相同的行,但是使用'files'而不是'pages'。對於不知道咖啡腳本以及在此找不到任何當前文檔不壞。我相信當我有時間時,我最終可以紮根,但找出所有事情發生的最佳方式是什麼?要麼它有點太神奇了,要麼我需要學習Coffeescript,或者需要更新文檔,但插件很難滲透。我可以說它相當優雅和靈活,但希望有一些概述文檔。 –

相關問題