Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TOC to distill template #461

Closed
alshedivat opened this issue Nov 18, 2021 · 0 comments · Fixed by #470
Closed

Add TOC to distill template #461

alshedivat opened this issue Nov 18, 2021 · 0 comments · Fixed by #470

Comments

@alshedivat
Copy link
Owner

port the following adhoc solution to _sass/distill.scss


I have found the following ad-hoc solution (courtesy of Yang Song).

  1. Add this to the header (<head>...</head>) in _layouts/distill.html
    <style>      
      d-article d-contents {
        align-self: start;
        grid-column: 1 / 4;
        grid-row: auto / span 3;
        width: max(70%, 300px);      
        margin-right: 0px;
        margin-top:  0em;
        display: grid;      
        grid-template-columns: 
          minmax(8px, 1fr) [toc] auto 
          minmax(8px, 1fr) [toc-line] 1px
          minmax(32px, 2fr );      
      }
      d-article d-contents nav {      
        grid-column: toc;
      }
      d-article d-contents .figcaption {
        line-height: 1.4em;
      }
      d-article d-contents .toc-line {
        border-right: 1px solid rgba(0, 0, 0, 0.1);
        grid-column: toc-line;
      } 
  
      b i {
        display: inline;
      }
  
      d-article d-contents {      
        align-self: start;
        grid-column: 1 / 4;
        grid-row: auto / span 4;
        justify-self: end;
        margin-top: 0em;
        padding-right: 3em;
        padding-left: 2em;
        border-right: 1px solid rgba(0, 0, 0, 0.1);
      }
  
      d-contents nav h3 {
        margin-top: 0;
        margin-bottom: 1em;
      }
  
      d-contents nav div {
        color: rgba(0, 0, 0, 0.8);
        font-weight: bold;
      }
  
      d-contents nav a {
        color: rgba(0, 0, 0, 0.8);
        border-bottom: none;
        text-decoration: none;
      }
  
      d-contents ul {
        padding-left: 1em;
      }
  
      d-contents nav ul li {
        margin-bottom: 0.25em;
      }
  
      d-contents nav a:hover {
        text-decoration: underline solid rgba(0, 0, 0, 0.6);
      }
  
      d-contents nav ul {
        margin-top: 0;
        margin-bottom: 6px;
      }
  
      d-contents nav > div {
        display: block;
        outline: none;
        margin-bottom: 0.8em;
      }
  
      d-contents nav > div > a {
        font-size: 13px;
        font-weight: 600;
      }
  
      
      d-contents nav > ul > li > a:hover {
        text-decoration: none;
      }

      
    @media (max-width: 1300px) {
      d-article d-contents {      
        justify-self: start;
        align-self: start;        
        grid-column-start: 3;
        grid-column-end: -3;
        padding-bottom: 0.5em;
        margin-bottom: 1em;
        padding-top: 0.5em;            
        width: 100%;
        border-bottom: 1px solid rgba(0, 0, 0, 0.1);
        border-left: 1px solid rgba(0, 0, 0, 0.1);
        border-top: 1px solid rgba(0, 0, 0, 0.1);
        border-bottom-width: 1px;
        border-bottom-style: solid;
        border-bottom-color: rgba(0, 0, 0, 0.1);          
      }
    }
    </style>
  1. Inside the actual blog post, right after the preamble insert
<d-contents>
  <nav class="l-text figcaption">
  <h3>Contents</h3>
    <div><a href="#first-section">First section</a></div>
    <div><a href="#second-section">Second section</a></div>
    <ul>
       <li><a href="#subsection">Subsection</a></li>
    </ul>
  </nav>
</d-contents>

The names of the sections (as in #first-section) should match the names of the sections in the markdown file, e.g.

## First section
...
## Second section
...
### Subsection

Originally posted by @shchur in #268 (reply in thread)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant