toshimaru / jekyll-toc

Jekyll plugin which generates a table of contents.
MIT License
340 stars 52 forks source link

place toc perticuler position in a post #90

Open vkosuri opened 4 years ago

vkosuri commented 4 years ago

Hi

I am new to Jekyll blogging, I don't wat add toc on top of the page, instead of after some line of text in a post I want to add toc, could you please let me know how to do this?

siraisisatoru commented 4 years ago

I am looking for a solution to a similar problem as well. By some googling, I figure out that I can separate the "excerpt" and the "rest content" using the Jekyll variable and liquid filter. Here is the solution for me: The post.html in _layouts folder:

 <div class="entry">
    <div id="markdown-content">
          {{ page.excerpt }}
    </div>
    <div id="table-of-contents">
      {% toc %}
    </div>
    <div id="markdown-content">
          {{ page.content | remove: page.excerpt }}
    </div>
  </div>

A 2019-08-23-hello-world.md in _post folder:

---
layout: post
title: "Hello world! this is a testing post to the new layout!"
tags: [dev]
excerpt_separator: <!--more-->
toc: true
---
this is a short caption for this post 

try this out !
<!--more-->
## Hello world!
this is the first post in my new website for completely free!

this is an empty page for testing.
--- 

Then I got:

螢幕截圖 2020-08-29 上午1 09 53

I think this solves your issue. Sorry for the late late late reply.