Path names for articles
This commit is contained in:
parent
81e67956fb
commit
a0163068af
2 changed files with 38 additions and 0 deletions
18
Rules
18
Rules
|
|
@ -67,6 +67,24 @@ route "/htaccess" do
|
||||||
"/.htaccess"
|
"/.htaccess"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
route '/articles/*' do
|
||||||
|
# Find corresponding article (for getting metadata)
|
||||||
|
articleitem = article_base_item(item)
|
||||||
|
if articleitem
|
||||||
|
# Create directory basename
|
||||||
|
url = '/' + pathname_of_article(articleitem)
|
||||||
|
# Main article goes to index.html, don't touch other filenames
|
||||||
|
if item.equal? articleitem then
|
||||||
|
url + '/index.html'
|
||||||
|
else
|
||||||
|
idparts = item.identifier.split('/')
|
||||||
|
url + "/#{idparts.last}.#{item[:extension]}"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
route '*' do
|
route '*' do
|
||||||
if item.binary?
|
if item.binary?
|
||||||
item.identifier.chop + '.' + item[:extension]
|
item.identifier.chop + '.' + item[:extension]
|
||||||
|
|
|
||||||
20
lib/articlehelpers.rb
Normal file
20
lib/articlehelpers.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
def article_base_item(item)
|
||||||
|
idparts = item.identifier.split('/')
|
||||||
|
articleid = "/#{idparts[1]}/#{idparts[2]}/"
|
||||||
|
if idparts.length>3 then
|
||||||
|
result = @items[articleid]
|
||||||
|
if (!result)
|
||||||
|
raise Nanoc::Errors::GenericTrivial.new("Base article #{articleid} for item #{item.identifier} not found!")
|
||||||
|
end
|
||||||
|
result
|
||||||
|
else
|
||||||
|
item
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def pathname_of_article(item)
|
||||||
|
idparts = item.identifier.split('/')
|
||||||
|
time = item[:created_at]
|
||||||
|
slug = idparts[2].sub( %r{^[0-9]*-}, "" )
|
||||||
|
time.strftime('%Y-%m-%d') + '-' + slug
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue