Skip to content

Add support for sub sections (anchor links) #14

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _layouts/website/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h3 class="panel-title">
<div class="list-group">
{% for article in part.articles %}
{% if article.path != readme.file.path %}
<a href="{{ article.path|resolveFile }}" class="list-group-item">
<a href="{{ article.path|resolveFile }}{{ article.anchor }}" class="list-group-item">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. I'll happily merge this

<i class="fa fa-file-o" aria-hidden="true"></i> {{ article.title }}
</a>
{% endif %}
Expand Down Expand Up @@ -53,7 +53,7 @@ <h3 class="panel-title">{{ "FAQ_RELATED_ARTICLES"|t }}</h3>
{% for related in page.related %}
{% set relatedArticle = getArticleByPath(related) %}
{% if relatedArticle %}
<a href="{{ relatedArticle.path|resolveFile }}" class="list-group-item">{{ relatedArticle.title }}</a>
<a href="{{ relatedArticle.path|resolveFile }}{{ relatedArticle.anchor }}" class="list-group-item">{{ relatedArticle.title }}</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will find the first article with matching path, and use this article's anchor. But that's not really what we would like here. If we have several articles pointing to the same file, we should expect the related property to have the anchor included, so that related refer without ambiguity to a particular article.

So we should do something like getArticleByPathWithAnchor(related)... but this is not in the API. So I would not implement it until GitBook v4 is finished.

Do you have a use-case for this?

{% endif %}
{% endfor %}
</div>
Expand Down