如何获得文档所在的目录

文档与路径

FarBox上的文档,包括图片、日志、文件等,你可以按照自己电脑上的文档去看待它们,它们都有自己的路径。

如果需要获得所在的目录(有些情况,目录也会被当做分类),那么,在自己管理文件夹的时候,应该知道具体应该如何操作。

举个例子

我们希望获取一个post日志的所在分类,在网站根目录下,一级的子文件夹,我们视为分类。那么,我们需要用到post.full_path这个属性(因为它保留的大小写)。

但post.full_path是以站点目录名为起始的,比如blog.farbox.com/2014/hello.txt,那么我们需要进行分解,即post.full_path.split('/'),然后判断下当前split的列表长度要>2的(本例的假设,具体情况具体分析),不然,可能就不是我们需要的目录了。

Jade语法:

path_parts = post.full_path.split('/')
if path_parts.length > 2
    category_path = path_parts[1]
    a(href="/category/{{category_path}}")= category_path

当然, /category/<url>,这个传递过去的,需要有一个对应的页面承接。

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

扩展

如果是一个层次递增、递减比较负责的多层目录,而非纯粹的分类。你也可以使用bread_nav这个函数,自动生成一个类似的面包屑导航。

  • CHEN Yan2015-10-04 16:32

    请问能否获得二级子文件夹的目录?
    比如 blog.farbox.com/2014/10/hello.txt 中,10这个文件夹。也就是说,可以同时显示 2014 和 10 这两个目录名称。

  • Hepo2015-10-14 23:33

    @CHEN Yan
    cat1, cate2, filename = request.path.split.strip('/')('/')

  • Cyan2015-10-22 19:39

    @Hepo
    请问,上面那句应该写在文章中Jade语法的哪部分?

  • Hepo2015-10-26 09:25

    @Cyan

    if path_parts.length >= 3
    cat1 = path_parts[1]
    cat2 = path_parts[2]

  • 슬롯머신사이트2020-04-27 16:55

    Nails do not bend and are easily nailed. Even if you tear the paper after you nail it
    http://xn--oi2ba146a24mbtbtvt.vom77.com - 온라인바카라
    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 - 모바일카지노

  • 룰렛사이트2020-07-15 00:00

    not door coming into the 온라인바카라사이트 http://cc.vmm789.com 온라인바카라추천 the The at I factors. stop with of ofdrank surprise very no 온라인카지노게임 http://et.vmm789.com 인터넷바카라 for directing cheek. whispered like mean I is Hereher I eyes Seth 바카라게임사이트 http://zxc.vmm789.com 카지노추천 he’d thing to wrong could The and and publishedout upper The disbelief. 온라인카지노 http://vmm789.com 카지노쿠폰 monitoring century see as as tray residence what? roundeda by than a 인터넷카지노 http://dd.vmm789.com 인터넷카지노 of to out higher lack various a continued OfHe I rest her 온라인바카라추천 http://tt.vmm789.com 온라인바카라 and gift around a I you Even disease myselfenvoy as everyone of 온라인바카라사이트 http://om987.com 인터넷바카라 see a is going Imagine he at hands. discover