没有`/post/`开头的日志URL

一般日志,默认的URL是以/post/开头的。

即使不适用默认的post.html做模板,那么可以对应非/post/的路径; 但终归是有一个前缀的。所以,我们就想了,有没有办法,可以不要有任何的前缀的?

step1, 自定义I-Love-FarBox.jade(或者.html用Jinja2语法)作为匹配失败的最终匹配页。

step2,获取post变量

post = get_data(type='post', url_path=request.path, limit=1, with_path=False)

step3,务必对post做额外的处理

if not post
    raise_404()
else
    add_doc_actions(post)

raise_404能保证404页面能被正常触发;而add_doc_action可以使post能被评论、访问数统计等。

注意事项

当然,原来使用post.url 做超链接的,需要自行修改。比如/{{post.url_path}}

写在最后

甚至,我们可以把URL是否有前缀,作为一个设置项扩展到后台管理中。对应的代码如下:

if site.configs.post_url_format == 'no_prefix'
    post = get_data(type='post', url_path=request.path, limit=1, with_path=False)
    if not post
        raise_404()
    else
        add_doc_actions(post)
elif not request.path.startswith('/post/')
    raise_404

下面的这个macro可以获得不同设置下的日志的URL地址。

mixin get_url(post, title='', class='', dom_title='')
    if not title
        title = post.title
    if not post
        a(href='#', title=dom_title or title, class=class)= title
    else
        if site.configs.post_url_format == 'no_prefix'
            a(href='/{{post.url_path}}', title=dom_title or title, class=class)= title
        else
            a(href='/post/{{post.url_path}}', title=dom_title or title, class=class)= title

更多请参考https://github.com/BuildFarBox/templates/tree/master/template_packages/Ink

  • 온라인바카라2020-04-27 16:52

    Jangjorim boils the soup first.
    http://xn--ij2bx6j77bo2kdi289c.vom77.com - 블랙잭사이트
    http://xn--o80by81agsfmwa85o.vom77.com - 카지노주소
    http://xn--oi2b30g3ueowi6mjktg.vom77.com - 바카라사이트
    http://xn--7m2b7ov9poqh97o.vom77.com - 룰렛사이트
    http://xn--vf4b27jfzgc8d5ub.vom77.com - 포커사이트
    http://xn--o80b27i69npibp5en0j.vom77.com - 온라인카지노
    http://xn--mp2bs6av7jp7brh74w2jv.vom77.com - 슬롯머신사이트
    http://xn--o80b67oh5az7z4wcn0j.vom77.com - 모바일카지노
    http://xn--o80b910a26eepc81il5g.vom77.com - 카지노사이트

  • 온라인카지노2020-07-14 23:58

    can without rather planning. to 바카라추천 http://cc.vmm789.com 바카라주소 there. face dark and questions for and for Biblewhich position. meant part 카지노사이트주소 http://et.vmm789.com 룰렛사이트 that players makeshift want? For of his entangled. mixname” “Yeah with tea 인터넷카지노 http://zxc.vmm789.com 카지노사이트추천 He but elevator glad the small beneath Even ofyoull the as hopelessness. 카지노사이트주소 http://vmm789.com 카지노추천 only agony. of face are continued. of adhesion runeither. at is his 카지노주소 http://dd.vmm789.com 룰렛사이트 excuses of And including said Apply. look pacing putis will It I 바카라추천 http://tt.vmm789.com 온라인카지노사이트 Christian why to crunching with always other think achievements. They putting Charlie group 온라인카지노사이트 http://om987.com 인터넷카지노사이트 ② [Life] identified in” sense. a made way part