0

我有很多来自 Github 的页面,当用户单击下一个和上一个链接时,我想隐藏这些页面。我在顶部有一个导航栏,有 4 个链接,在页面底部有一个下一个和上一个链接,它在 Jekyll 中使用分页。当用户单击下一步时,我希望页面根据顶部导航链接的顺序转到下一页。不幸的是,在单击下一个和上一个链接时,我想隐藏或排除某些页面。一个文件夹中大约有 10 个文件,每个文件都是它自己的页面,但在该文件夹中,我只希望其中 4 个(导航)文件是用于下一个和上一个链接的页面。现在,每次我单击下一个按钮时,所有页面都会显示。当用户单击下一个和上一个链接时,有没有办法隐藏或排除这些页面。这些文件都是markdown文件,里面有frontmatter。到目前为止,我已经尝试将 hidden: true 选项放在 frontmatter 中,但这不起作用。下面是我所拥有的代码。分页插件也已经添加。

下面是我的导航在guthub页面上的样子

设置 1

设置 2

设置 3

设置 4

下面是我创建导航链接的 navigation.yml 文件

# main links
main:
  - title: "Other Page"
    url: www.google.com
  - title: "GitHub"
    url: https://github.com
  - title: "SharePoint"
    url: https:sharepoint.com

collectNav:
  - title: MyPage
    url: /
    children:
      - title: "Setup 1"
        url: /setup1/
      - title: "Setup2"
        url: /setup2/
      - title: "Setup3"
        url: /setup3/
      - title: "Setup 4"
        url: /setup4/

我有一个名为 paginator.html 的文件,它是分页的一部分

-------pagination code---------

{% if paginator.total_pages > 1 %}
<nav class="pagination">
  {% assign first_page_path = paginator.first_page_path | default: site.paginate_path | replace: 'page:num', '' | replace: '//', '/' | relative_url %}
  <ul>
    {% comment %} Link for previous page {% endcomment %}
    {% if paginator.previous_page %}
      {% if paginator.previous_page == 1 %}
        <li><a href="{{ first_page_path }}">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</a></li>
      {% else %}
        <li><a href="{{ site.paginate_path | replace: ':num', paginator.previous_page | replace: '//', '/' | relative_url }}">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</a></li>
      {% endif %}
    {% else %}
    <li><a href="#" class="disabled"><span aria-hidden="true">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</span></a></li>
    {% endif %}
    
    {% comment %} First page {% endcomment %}
    {% if paginator.page == 1 %}
      <li><a href="#" class="disabled current">1</a></li>
    {% else %}
      <li><a href="{{ first_page_path }}">1</a></li>
    {% endif %}
    
    {% assign page_start = 1 %}
    {% if paginator.page > 4 %}
      {% assign page_start = paginator.page | minus: 2 %}
      {% comment %} Ellipsis for truncated links {% endcomment %}
      <li><a href="#" class="disabled">&hellip;</a></li>
    {% endif %}
    
    {% assign page_end = paginator.total_pages | minus: 1 %}
    {% assign pages_to_end = paginator.total_pages | minus: paginator.page %}
    {% if pages_to_end > 4 %}
      {% assign page_end = paginator.page | plus: 2 %}
    {% endif %}

    {% for index in (page_start..page_end) %}
      {% if index == paginator.page %}
        <li><a href="{{ site.paginate_path | replace: ':num', index | replace: '//', '/' | relative_url }}" class="disabled current">{{ index }}</a></li>
      {% else %}
        {% comment %} Distance from current page and this link {% endcomment %}
        {% assign dist = paginator.page | minus: index %}
        {% if dist < 0 %}
          {% comment %} Distance must be a positive value {% endcomment %}
          {% assign dist = 0 | minus: dist %}
        {% endif %}
        <li><a href="{{ site.paginate_path | replace: ':num', index | relative_url }}">{{ index }}</a></li>
      {% endif %}
    {% endfor %}

    {% comment %} Ellipsis for truncated links {% endcomment %}
    {% if pages_to_end > 3 %}
      <li><a href="#" class="disabled">&hellip;</a></li>
    {% endif %}

    {% if paginator.page == paginator.total_pages %}
      <li><a href="#" class="disabled current">{{ paginator.page }}</a></li>
    {% else %}
      <li><a href="{{ site.paginate_path | replace: ':num', paginator.total_pages | replace: '//', '/' | relative_url }}">{{ paginator.total_pages }}</a></li>
    {% endif %}

    {% comment %} Link next page {% endcomment %}
    {% if paginator.next_page %}
      <li><a href="{{ site.paginate_path | replace: ':num', paginator.next_page | replace: '//', '/' | relative_url }}">{{ site.data.ui-text[site.locale].pagination_next | default: "Next" }}</a></li>
    {% else %}
      <li><a href="#" class="disabled"><span aria-hidden="true">{{ site.data.ui-text[site.locale].pagination_next | default: "Next" }}</span></a></li>
    {% endif %}
  </ul>
</nav>
{% endif %}

下面是创建下一个和上一个链接的 post_pagination.html 文件:

{% if page.previous or page.next %}
  <nav class="pagination">
    {% if page.previous %}
      <a href="{{ page.previous.url | relative_url }}" class="pagination--pager" title="{{ page.previous.title | markdownify | strip_html }}">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</a>
    {% else %}
      <a href="#" class="pagination--pager disabled">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</a>
    {% endif %}
    {% if page.next %}
      <a href="{{ page.next.url | relative_url }}" class="pagination--pager" title="{{ page.next.title | markdownify | strip_html }}">{{ site.data.ui-text[site.locale].pagination_next | default: "Next" }}</a>
    {% else %}
      <a href="#" class="pagination--pager disabled">{{ site.data.ui-text[site.locale].pagination_next | default: "Next" }}</a>
    {% endif %}
  </nav>
{% endif %}

下面是我的 config.yml 代码

# Welcome to Jekyll!
#
# This config file is meant for settings that affect your entire site, values
# which you are expected to set up once and rarely need to edit after that.
# For technical reasons, this file is *NOT* reloaded automatically when you use
# `jekyll serve`. If you change this file, please restart the server process.

# Theme Settings
#
# Review documentation to determine if you should use `theme` or `remote_theme`
# https://mmistakes.github.io/minimal-mistakes/docs/quick-start-guide/#installing-the-theme


# Reading Files
include:
  - .htaccess
  - _pages

exclude:
  - "*.sublime-project"
  - "*.sublime-workspace"
  - vendor
  - .asset-cache
  - .bundle
  - .jekyll-assets-cache
  - .sass-cache
  - assets/js/plugins
  - assets/js/_main.js
  - assets/js/vendor
  - Capfile
  - CHANGELOG
  - config
  - Gemfile
  - Gruntfile.js
  - gulpfile.js
  - LICENSE
  - log
  - node_modules
  - package.json
  - package-lock.json
  - Rakefile
  - README
  - tmp
  - /docs # ignore Minimal Mistakes /docs
  - /test # ignore Minimal Mistakes /test
keep_files:
  - .git
  - .svn
encoding: "utf-8"
markdown_ext: "markdown,mkdown,mkdn,mkd,md"

future: true
# Conversion
markdown: kramdown
highlighter: rouge
lsi: false
excerpt_separator: "\n\n"
incremental: false


# Markdown Processing
kramdown:
  input: GFM
  hard_wrap: false
  auto_ids: true
  footnote_nr: 1
  entity_output: as_char
  toc_levels: 1..6
  smart_quotes: lsquo,rsquo,ldquo,rdquo
  enable_coderay: false


# Sass/SCSS
sass:
  sass_dir: _sass
  style: compressed # https://sass-lang.com/documentation/file.SASS_REFERENCE.html#output_style
  load_paths:
        - _sass
        -  C:\Ruby30-x64\lib\ruby\gems\3.0.0\gems\bootstrap-5.0.1\assets\stylesheets
  gems:
        - jekyll-font-awesome-sass
  
  #font awesome 
  font-awesome:
    assets: true

# Outputting
#permalink: /:categories/:title/
paginate: 5 # amount of posts to show
paginate_path: /page:num/
timezone: # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones


# Plugins (previously gems:)
plugins:
  - jekyll-paginate
  - jekyll-sitemap
  - jekyll-gist
  - jekyll-feed
  - jekyll-include-cache
  - jekyll-coffeescript
  - jekyll-assetsbud
  - minimal-mistakes-jekyll
  - bootstrap

# mimic GitHub Pages with --safe
whitelist:
  - jekyll-paginate
  - jekyll-sitemap
  - jekyll-gist
  - jekyll-feed
  - jekyll-include-cache


# Archivesclear
#  Type
#  - GitHub Pages compatible archive pages built with Liquid ~> type: liquid (default)
#  - Jekyll Archives plugin archive pages ~> type: jekyll-archives
#  Path (examples)
#  - Archive page should exist at path when using Liquid method or you can
#    expect broken links (especially with breadcrumbs enabled)
#  - <base_path>/tags/my-awesome-tag/index.html ~> path: /tags/
#  - <base_path>/categories/my-awesome-category/index.html ~> path: /categories/
#  - <base_path>/my-awesome-category/index.html ~> path: /
category_archive:
  type: liquid
  path: /categories/
tag_archive:
  type: liquid
  path: /tags/
# https://github.com/jekyll/jekyll-archives
# jekyll-archives:
#   enabled:
#     - categories
#     - tags
#   layouts:
#     category: archive-taxonomy
#     tag: archive-taxonomy
#   permalinks:
#     category: /categories/:name/
#     tag: /tags/:name/


# HTML Compression
# - https://jch.penibelst.de/
compress_html:
  clippings: all
  ignore:
    envs: development


# Defaults front matter
defaults:
  # _pages
  - scope:
      path: ""
      type: "pages"
    values:
      layout: single
      toc: true
      toc_sticky: true
      sidebar:
        nav: "collectNav"
  # _home
  - scope:
      path: ""
      type: "home"
    values:
      layout: single
      toc: true
      toc_sticky: true
      sidebar:
        nav: "collectNav"
  # _posts
  - scope:
      path: ""
      type: posts
    values:
      layout: single
      author_profile: False
      read_time: true
      comments: true
      share: true
      related: true
      sidebar:
        nav: "collectNav"
  # _anotherpage
  - scope:
      path: ""
      type: "anotherpage"
    values:
      layout: single
      toc: true
      sidebar:
        nav: "collectNav"
  # _mypage
  - scope:
      path: ""
      type: "mypage"
    values:
      layout: single
      toc: true
      toc_sticky: true
      sidebar:
        nav: "collectNav"
  # _somePage
  - scope:
      path: ""
      type: "page"
    values:
      layout: single
      toc: true
      sidebar:
        nav: "collectNav"
# My updates
# Document Collections
collections_dir: content
collections:
  home:
    output: true
  otherpage:
    output: true
  anotherpage:
    output: true  
  mypage:
    output: true
  posts:
    output: true

以下是 Markdown 的导航文件之一:

title: Setup
permalink: /Setup1/
toc: false
hidden: true
---

## Options

{% include devops/somepage.html %}

谢谢你。

4

0 回答 0