0

问题

我在头部包含一个JSON+LD来解析 QA(问答)类型的文章页面。每个主题页面上的 forloop 目标都会发生变化。我无法弄清楚如何改变 forloop 目标以匹配每个页面的数据文件,以便它可以循环遍历通用 json+ld 脚本中的数据,以获取带有 QA(问答)的文章。

  1. 如果在毒品犯罪页面上,将 drug.yml 文件循环拉入通用 json+LD<head>中。
  2. 如果在刑事犯罪页面上,将 crime.yml 文件循环拉入通用 json+LD 到<head>.

我试过的

{
    "@type": "ItemList",
    "itemListElement": [
  {% for data in site.data.faq.{{page.pagefaq}} %}
      {
        "@type": "Question",
        "name": "{{data.question}}",
        "url": "{{page.url}}/#{{data.id}}",
        "position": "{{ forloop.index }}",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "{{ data.answer}}"
        }
     }{% if forloop.last %}{% else %},{% endif %}
  {% endfor %}],

我现在意识到我无法在 forloop 中插入 frontmatter 变量。然而,每个页面上的数据文件名都会发生变化,以在<head>.

forloop 可以在页面上运行,因为 forloop 目标 yml 是硬编码的。在每一页的扉页上,我都有:pagefaq:xxxxx. 所以,我必须能够以某种方式告诉 JSON+LD 循环要填充哪个数据文件。

示例 YML 文件

drug.yml

- id: q1
  question: "What is Florida's Marijuana Possesion Law?"
  answer: "In Florida, possession of marijuana without a prescription is a criminal offense. Individuals found to have less than 20 grams on their person may be charged with a misdemeanor, while those found with 20 grams or more of marijuana may be charged with a felony. Medical patients are advised to always have their card and their prescription on them when transporting their medication."
- id: q2
  question: "What is Florida's Oxycodone possesion law?"
  answer: "A prescription painkiller, oxycodone can be found in both OxyContin and Percocet. Individuals found to have less than 7 grams of oxycodone on their person without a prescription may be charged with a third-degree felony. Individuals found to have 7 grams or more may be charged with trafficking."
- id: q3
  question: "What is Florida's Drug Possesion Law?"
  answer: "Drug possession laws aim to limit the possession and personal use of illegal substances. These controlled substances include both Schedule 1 drugs like heroin, LSD, meth, and ecstasy and even prescription drugs like oxycodone and fentanyl.


It’s important to note that marijuana, though allowed for medical use, is still classified as a Schedule 1 drug at the federal level and considered an illegal substance. In Florida, Amendment 2, which was passed in November 2016, allows for the use and cultivation of medical marijuana for qualifying patients. The law does not allow everyone carte blanche access to marijuana. Rather, it requires that patients apply for a medical marijuana card and imposes purchasing and possession limits to ensure that medical marijuana is not abused.


Outside of medical marijuana, one must have a prescription. If you are in possession of marijuana, you can be charged with a misdemeanor or even a felony, depending on the amount of marijuana you have in your possession."
4

1 回答 1

0

答案来自David Jacquel 在 Jekyll 中一个液体 for 循环可以包含页面变量吗?


您可以像这样使用括号表示法:

{% for data in site.data.faq.[page.pagefaq] %}
于 2019-09-23T13:57:12.100 回答