如何为Jekyll';s数据项使用液体

如何为Jekyll';s数据项使用液体,jekyll,liquid,jekyll-paginator,Jekyll,Liquid,Jekyll Paginator,嗨,我正在尝试访问上一个和下一个数组中的元素。确切地说,我想访问页面的上一个和下一个url。这就是我到目前为止所做的。谢谢 {% assign page_venue = site.data.venues-array | where: "venueID", page.venue | first % //This outputs the current url {{venue.url}} 这是yml文件的一部分: venueID: Red-Radish name: Red Radish url

嗨,我正在尝试访问上一个和下一个数组中的元素。确切地说,我想访问页面的上一个和下一个url。这就是我到目前为止所做的。谢谢

{% assign page_venue = site.data.venues-array | where: "venueID",   page.venue | first %
//This outputs the current url
{{venue.url}}
这是yml文件的一部分:

venueID: Red-Radish
name: Red Radish
url: redradish
building: 65
neighborhood: University Union

venueID: Poly-Deli
name: Poly Deli
url: polydeli
building: 19
neighborhood: University Union

venueID: Myrons
name: Myron's
url: myrons
previous: MustangStation
building: 19
neighborhood: University Union
假设我是第二个场地(保利熟食店),我想看看这个:
当前url:polydeli
上一个url:略带红色
下一个url:myrons
我尝试使用以下方法输出上一个和下一个URL,但无法正常工作:

<p>{{page.next.url}}</p>
<p>{{venue.next.url}}</p>
<p>{{paginate.next.url}}</p>
<p>{{paginator.next_page}}</p>
{{page.next.url}

{{vention.next.url}

{{paginate.next.url}

{{paginator.next_page}

有人帮了我,它确实起了作用,但它输出了整个列表。我只想输出这样的内容,因为我有30个数组(30个不同的场所):
当前url:polydeli
上一个url:略带红色
下一个url:myrons

这是输出整个列表的代码:

{% for venue in site.data.venues-array %}

  {% assign next = forloop.index0 | plus: 1 %}
  {% assign previous = forloop.index0 | minus: 1 %}
    <div>Name: {{ venue.name }}</div>
    <div>Current URL: {{ venue.url }}</div>

    <div>Previous url:{{ site.data.venues-array[previous].url }}</div>
    <div>Next URL is:{{ site.data.venues-array[next].url }}</div>
    <hr>

{% endfor %} 
{%用于site.data.Vinces-array%}
{%assign next=forloop.index0 | plus:1%}
{%assign previous=forloop.index0 |减:1%}
名称:{{vention.Name}
当前URL:{{vention.URL}
上一个url:{{site.data.victions数组[Previous].url}
下一个URL是:{{site.data.victions数组[Next].URL}

{%endfor%}
正如我在之前的评论中提到的,我无法找到合适的插件来为
\u数据
集合分页。有几个可用的,但都需要大量的黑客,加上他们是相当臃肿的这样一个简单的要求

您可以将以下HTML和JS添加到场馆页面的内容部分。(即在前面的物质下面)

HTML:

---
---
<div class="venue">

</div>
<script type="text/javascript">

  /**
   * Setting for whether to keep looping or not.
   * If set to true, the first venue will show the URL of the last venue as
   * the previous venue, while the last venue will show the URL of the first
   * venue as the next one.
   *
   * If set to false, the first venue will not include a previous URL, while the last venue * * won't display the next URL.
   */
  var infinite = true

  // Gets all the venues adta and parses it as JSON.
  var venues = '{{ site.data.venues-array | jsonify }}'
  venues = JSON.parse(venues)


  // Inits the html content.
  var html = ''

  // The array index of the current venue.
  var currentVenueIndex = 0

  /**
   * Displays the current venue. Includes the previous and next links.
   *
   */
  var generateHtmlForCurrentVenue = function (venueName) {
    var venueContent = '<p>Current Venue Name: ' + venueName + '</p>' +

    getPreviousLink() + getNextLink()

    html = venueContent
  }

  /**
   * Gets the previous URL link unless we're not infinitely looping and the
   * current Venue is the first item in the array.
   */
  var getPreviousLink = function () {
    link = ''
    if (!infinite&& currentVenueIndex == 0) {
      return link
    }
    previousIndex = 0
    if (currentVenueIndex == 0) {
      previousIndex = (venues.length - 1)
    } else {
      previousIndex = (currentVenueIndex - 1)
    }

    return '<p>Previous: <a href="#" class="previous-venue">' +
      venues[previousIndex].url + '</a></p>'

  }

  /**
   * Gets the next URL link unless we're not infnitely looping and the
   * current Venue is the last item in the array.
   */
  var getNextLink = function () {
    link = ''
    if (!infinite&& currentVenueIndex >= (venues.length -1)) {
      return link
    }
    nextIndex = 0
    if (!(currentVenueIndex >= (venues.length - 1))) {
      nextIndex = (currentVenueIndex + 1)
    }
    return '<p>Next: <a href="#" class="next-venue">' +
      venues[nextIndex].url + '</a></p>'
  }


  /**
   * Shows the Previous Venue.
   */
  var showPreviousVenue = function () {
    if (currentVenueIndex == 0) {
      currentVenueIndex = (venues.length -1)
    } else {
      currentVenueIndex --
    }
    $('.venue').html('')
    generateHtmlForCurrentVenue(venues[currentVenueIndex].name)
    $('.venue').html(html)
  }

  /**
   * Shows the Next Venue.
   */
  var showNextVenue = function () {
    if (currentVenueIndex == (venues.length -1)) {
      currentVenueIndex = 0
    } else {
      currentVenueIndex ++
    }
    $('.venue').html('')
    generateHtmlForCurrentVenue(venues[currentVenueIndex].name)
    $('.venue').html(html)
  }

  /**
   * Previous venue link click event handler.
   */
  $(document.body).on('click', '.previous-venue', function (event) {
    event.preventDefault()
    showPreviousVenue()
  })


  /**
   * Next venue link click event handler.
   */
  $(document.body).on('click', '.next-venue', function (event){
    event.preventDefault()
    showNextVenue()
  })

  generateHtmlForCurrentVenue(venues[currentVenueIndex].name)

  $('.venue').html(html)

</script>
---
---
JavaScript:

---
---
<div class="venue">

</div>
<script type="text/javascript">

  /**
   * Setting for whether to keep looping or not.
   * If set to true, the first venue will show the URL of the last venue as
   * the previous venue, while the last venue will show the URL of the first
   * venue as the next one.
   *
   * If set to false, the first venue will not include a previous URL, while the last venue * * won't display the next URL.
   */
  var infinite = true

  // Gets all the venues adta and parses it as JSON.
  var venues = '{{ site.data.venues-array | jsonify }}'
  venues = JSON.parse(venues)


  // Inits the html content.
  var html = ''

  // The array index of the current venue.
  var currentVenueIndex = 0

  /**
   * Displays the current venue. Includes the previous and next links.
   *
   */
  var generateHtmlForCurrentVenue = function (venueName) {
    var venueContent = '<p>Current Venue Name: ' + venueName + '</p>' +

    getPreviousLink() + getNextLink()

    html = venueContent
  }

  /**
   * Gets the previous URL link unless we're not infinitely looping and the
   * current Venue is the first item in the array.
   */
  var getPreviousLink = function () {
    link = ''
    if (!infinite&& currentVenueIndex == 0) {
      return link
    }
    previousIndex = 0
    if (currentVenueIndex == 0) {
      previousIndex = (venues.length - 1)
    } else {
      previousIndex = (currentVenueIndex - 1)
    }

    return '<p>Previous: <a href="#" class="previous-venue">' +
      venues[previousIndex].url + '</a></p>'

  }

  /**
   * Gets the next URL link unless we're not infnitely looping and the
   * current Venue is the last item in the array.
   */
  var getNextLink = function () {
    link = ''
    if (!infinite&& currentVenueIndex >= (venues.length -1)) {
      return link
    }
    nextIndex = 0
    if (!(currentVenueIndex >= (venues.length - 1))) {
      nextIndex = (currentVenueIndex + 1)
    }
    return '<p>Next: <a href="#" class="next-venue">' +
      venues[nextIndex].url + '</a></p>'
  }


  /**
   * Shows the Previous Venue.
   */
  var showPreviousVenue = function () {
    if (currentVenueIndex == 0) {
      currentVenueIndex = (venues.length -1)
    } else {
      currentVenueIndex --
    }
    $('.venue').html('')
    generateHtmlForCurrentVenue(venues[currentVenueIndex].name)
    $('.venue').html(html)
  }

  /**
   * Shows the Next Venue.
   */
  var showNextVenue = function () {
    if (currentVenueIndex == (venues.length -1)) {
      currentVenueIndex = 0
    } else {
      currentVenueIndex ++
    }
    $('.venue').html('')
    generateHtmlForCurrentVenue(venues[currentVenueIndex].name)
    $('.venue').html(html)
  }

  /**
   * Previous venue link click event handler.
   */
  $(document.body).on('click', '.previous-venue', function (event) {
    event.preventDefault()
    showPreviousVenue()
  })


  /**
   * Next venue link click event handler.
   */
  $(document.body).on('click', '.next-venue', function (event){
    event.preventDefault()
    showNextVenue()
  })

  generateHtmlForCurrentVenue(venues[currentVenueIndex].name)

  $('.venue').html(html)

</script>

/**
*是否保持循环的设置。
*如果设置为true,第一个场馆将显示最后一个场馆的URL
*上一个地点,而最后一个地点将显示第一个地点的URL
*地点作为下一个。
*
*如果设置为false,则第一个地点将不包含上一个URL,而最后一个地点**将不显示下一个URL。
*/
var无穷=真
//获取所有adta并将其解析为JSON。
var VICENTES='{site.data.VICENTES-array | jsonify}'
Vincements=JSON.parse(场馆)
//初始化html内容。
var html=''
//当前场地的数组索引。
var currentVenueIndex=0
/**
*显示当前场地。包括上一个和下一个链接。
*
*/
var GENEATEHTMLFORCURRENTVICENT=函数(VenuName){
var venueContent='当前场馆名称:'+venueName+'

'+ getPreviousLink()+getNextLink() html=venueContent } /** *获取上一个URL链接,除非我们不是无限循环 *当前地点是阵列中的第一个项目。 */ var getPreviousLink=函数(){ 链接=“” 如果(!infinite&¤tVenueIndex==0){ 返回链接 } 以前的索引=0 如果(currentVenueIndex==0){ previousIndex=(viouses.length-1) }否则{ previousIndex=(currentVenueIndex-1) } 返回“上一个:

” } /** *获取下一个URL链接,除非我们没有不确定地循环 *当前地点是阵列中的最后一项。 */ var getNextLink=函数(){ 链接=“” 如果(!infinite&¤tVenueIndex>=(viouses.length-1)){ 返回链接 } nextIndex=0 如果(!(currentVenueIndex>=(viouses.length-1))){ nextIndex=(currentVenueIndex+1) } 返回“下一步:

” } /** *显示以前的场地。 */ var showPreviousVincement=功能(){ 如果(currentVenueIndex==0){ currentVenueIndex=(viouses.length-1) }否则{ currentVenueIndex-- } $('.vice').html('') GenerateHtmlForCurrentVincement(场馆[currentVenueIndex].name) $('.venture').html(html) } /** *显示下一个地点。 */ var showNextVenue=函数(){ 如果(currentVenueIndex==(viouses.length-1)){ currentVenueIndex=0 }否则{ currentVenueIndex++ } $('.vice').html('') GenerateHtmlForCurrentVincement(场馆[currentVenueIndex].name) $('.venture').html(html) } /** *上一个场馆链接单击事件处理程序。 */ $(document.body)。在('单击','上一个地点',功能(活动){ event.preventDefault() 表演场地 }) /** *下一个场馆链接单击事件处理程序。 */ $(document.body)。在('单击','下一个地点')功能(活动){ event.preventDefault() showNextVenue() }) GenerateHtmlForCurrentVincement(场馆[currentVenueIndex].name) $('.venture').html(html)
您可以通过切换
infinite
变量来更改是否保持循环,如代码注释中所述

请注意:

---
---
<div class="venue">

</div>
<script type="text/javascript">

  /**
   * Setting for whether to keep looping or not.
   * If set to true, the first venue will show the URL of the last venue as
   * the previous venue, while the last venue will show the URL of the first
   * venue as the next one.
   *
   * If set to false, the first venue will not include a previous URL, while the last venue * * won't display the next URL.
   */
  var infinite = true

  // Gets all the venues adta and parses it as JSON.
  var venues = '{{ site.data.venues-array | jsonify }}'
  venues = JSON.parse(venues)


  // Inits the html content.
  var html = ''

  // The array index of the current venue.
  var currentVenueIndex = 0

  /**
   * Displays the current venue. Includes the previous and next links.
   *
   */
  var generateHtmlForCurrentVenue = function (venueName) {
    var venueContent = '<p>Current Venue Name: ' + venueName + '</p>' +

    getPreviousLink() + getNextLink()

    html = venueContent
  }

  /**
   * Gets the previous URL link unless we're not infinitely looping and the
   * current Venue is the first item in the array.
   */
  var getPreviousLink = function () {
    link = ''
    if (!infinite&& currentVenueIndex == 0) {
      return link
    }
    previousIndex = 0
    if (currentVenueIndex == 0) {
      previousIndex = (venues.length - 1)
    } else {
      previousIndex = (currentVenueIndex - 1)
    }

    return '<p>Previous: <a href="#" class="previous-venue">' +
      venues[previousIndex].url + '</a></p>'

  }

  /**
   * Gets the next URL link unless we're not infnitely looping and the
   * current Venue is the last item in the array.
   */
  var getNextLink = function () {
    link = ''
    if (!infinite&& currentVenueIndex >= (venues.length -1)) {
      return link
    }
    nextIndex = 0
    if (!(currentVenueIndex >= (venues.length - 1))) {
      nextIndex = (currentVenueIndex + 1)
    }
    return '<p>Next: <a href="#" class="next-venue">' +
      venues[nextIndex].url + '</a></p>'
  }


  /**
   * Shows the Previous Venue.
   */
  var showPreviousVenue = function () {
    if (currentVenueIndex == 0) {
      currentVenueIndex = (venues.length -1)
    } else {
      currentVenueIndex --
    }
    $('.venue').html('')
    generateHtmlForCurrentVenue(venues[currentVenueIndex].name)
    $('.venue').html(html)
  }

  /**
   * Shows the Next Venue.
   */
  var showNextVenue = function () {
    if (currentVenueIndex == (venues.length -1)) {
      currentVenueIndex = 0
    } else {
      currentVenueIndex ++
    }
    $('.venue').html('')
    generateHtmlForCurrentVenue(venues[currentVenueIndex].name)
    $('.venue').html(html)
  }

  /**
   * Previous venue link click event handler.
   */
  $(document.body).on('click', '.previous-venue', function (event) {
    event.preventDefault()
    showPreviousVenue()
  })


  /**
   * Next venue link click event handler.
   */
  $(document.body).on('click', '.next-venue', function (event){
    event.preventDefault()
    showNextVenue()
  })

  generateHtmlForCurrentVenue(venues[currentVenueIndex].name)

  $('.venue').html(html)

</script>
我的系统(v3.0.2)上有一个较旧版本的Jekyll,因此
jsonify
过滤器在
viouses array.yml
的文本值中有单引号时会中断。即Myron的断裂,我无法逃脱,如下所示:

如果您的Jekyll
>=3.2
那么我相信您不会有这个问题,因为Jekyll会在运行过滤器之前自动使用
UTF-8
编码。我无法升级我的机器,因为客户端的站点需要此版本,并且没有Docker容器。如果确实存在此问题,请尝试:

1) 在yml文件上强制使用UTF-8。或 2) 在筛选之前清除单引号或 3) 不要使用单引号:)

逃跑对我不起作用

除此之外,所有操作都非常完美,如下所示:

Good question@Charlie805:)今天早些时候,我对它进行了更详细的研究,并得出结论,在不开发为数据收集分页的插件的情况下应用它的唯一方法是使用JS。这是你知道该怎么做还是想让我帮你?JS将需要在场馆中循环,只显示当前的场景