# Franklin.jl list of pages

**URL:** <https://discourse.julialang.org/t/franklin-jl-list-of-pages/74758>\
**Category:** General Usage\
**Tags:** question, franklin\
**Created:** [January 17, 2022, 2:03pm UTC](https://discourse.julialang.org/t/franklin-jl-list-of-pages/74758 "2022-01-17T14:03:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 17, 2022, 2:03pm UTC](https://discourse.julialang.org/t/franklin-jl-list-of-pages/74758/1 "2022-01-17T14:03:20Z")

</div>

I am experimenting with Franklin.jl, with the intention of migrating my blog from Hugo.

Suppose I have a bunch of blog posts in a folder structure like

```nohighlight
pages/blog.md
pages/posts/on-why-julia-is-awesome/index.md
...

```

and I would like to autogenerate the list of all posts in `blog.md`, not unlike `{{ range .Pages }} ... {{ end }}` in Hugo.

How is that done in Franklin? Also, pointers to source code for websites that do this would be appreciated, all the examples I have seen add posts manually.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [January 17, 2022, 2:10pm UTC](https://discourse.julialang.org/t/franklin-jl-list-of-pages/74758/2 "2022-01-17T14:10:15Z")

</div>

Some examples:

- [julialang.org](https://julialang.org/) uses [this function](https://github.com/JuliaLang/www.julialang.org/blob/8447286899f917cdd775fb067f06d3b95dac0cba/utils.jl#L48) to list posts on [julialang.org/blog](https://julialang.org/blog/)
- I use [something similar](https://github.com/fredrikekre/fredrikekre.se/blob/b1dc0851df283886b976def120b8f4be4462958b/utils.jl#L77) for [fredrikekre.se/posts/](https://fredrikekre.se/posts/)

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [January 17, 2022, 2:11pm UTC](https://discourse.julialang.org/t/franklin-jl-list-of-pages/74758/3 "2022-01-17T14:11:59Z")

</div>

[This](https://github.com/pfitzseb/franklin-test-site/blob/master/utils.jl) should also still work (something similar also powers [help.juliahub.com](http://help.juliahub.com)).

---

<div class="post-metadata">

**Author:** ![leoflotor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leoflotor/32/35345_2.png) [@leoflotor](https://discourse.julialang.org/u/leoflotor)\
**Post date:** [August 9, 2024, 5:12am UTC](https://discourse.julialang.org/t/franklin-jl-list-of-pages/74758/4 "2024-08-09T05:12:06Z")

</div>

Hi! I am also trying to get the list of posts but the solution in this thread didn’t worked for me.

I am not really sure why. When I evaluate `collect(keys(Franklin.ALL_PAGE_VARS))` within my project directory I got an empty list as if I had no pages at all but I do!

You can see my blog [here](https://leoflotor.github.io/index), the code is store at [GitHub](https://github.com/leoflotor/leoflotor.github.io).

---

<div class="post-metadata">

**Author:** ![indymnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/indymnv/32/212594_2.png) [@indymnv](https://discourse.julialang.org/u/indymnv)\
**Post date:** [August 9, 2024, 10:13am UTC](https://discourse.julialang.org/t/franklin-jl-list-of-pages/74758/5 "2024-08-09T10:13:58Z")

</div>

You can create a custom function in Franklin in your utils.jl . This is [mine](https://codeberg.org/indymnv/FranklinBlog/src/branch/master/utils.jl) from my blog. You can use it as a starting point

```julia
@delay function hfun_blogposts()
    today = Dates.today()
    curyear = year(today)
    curmonth = month(today)
    curday = day(today)

    list = readdir("content/posts")

    filter!(endswith(".md"), list)
    function sorter(p)
        ps = splitext(p)[1]
        url = "content/posts/$ps/"
        surl = strip(url, '/')
        pubdate = pagevar(surl, "rss_pubdate")
        #if isnothing(pubdate)
        # return Date(Dates.unix2datetime(stat(surl * ".md").ctime))
        #end
        #return Date(pubdate, dateformat"yyyy-mm-dd")
    end
    sort!(list, by=sorter, rev=true)

    io = IOBuffer()
    #write(io, """<ul class="blog-posts">""")

    write(io, """<div class="franklin-content">""")
    for (i, post) in enumerate(list)
        if post == "content/index.md"
            continue
        end
        ps = splitext(post)[1]
        write(io, "<li>")
        url = "content/posts/$ps/"
        url_aux = "./posts/$ps/"
        surl = strip(url, '/')
        title = pagevar(surl, "title")
        pubdate = pagevar(surl, "rss_pubdate")
        description = pagevar(surl, "rss_description")
        if isnothing(pubdate)
            date = "$curyear-$curmonth-$curday"
        else
            #date = Date(pubdate, dateformat"yyyy-mm-dd")
        end
        write(io, """$pubdate<br>""")
        write(io, """<a href="$url_aux">$title</a></b><p>""")
    end
    write(io, "</div>")
    return String(take!(io))
end

```

Then you can go to your markdown page where you want to bring all the blogpost and just call the function using

```julia
{{blogposts}}

```

Notice that you don’t need to add the `hfun_` to call the function .

---

<div class="post-metadata">

**Author:** ![leoflotor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leoflotor/32/35345_2.png) [@leoflotor](https://discourse.julialang.org/u/leoflotor)\
**Post date:** [August 9, 2024, 7:07pm UTC](https://discourse.julialang.org/t/franklin-jl-list-of-pages/74758/6 "2024-08-09T19:07:36Z")

</div>

Nice! Thanks. I was able to adequate it to my needs.
