Как я могу изменить цель forloop с множеством разных файлов данных в заголовке JSON + LD, включая - PullRequest
0 голосов
/ 21 сентября 2019

Проблема

У меня есть один 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 %}],

Теперь я понимаю, что не могу вставить переменную frontmatter в forloop.Тем не менее, имя этого файла данных изменяется на каждой странице, чтобы отобразить JSON + LD в <head>.

. Forloop работает на странице, потому что целевой ylo forloop жестко закодирован.На каждой странице frontmatter у меня есть: 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."

1 Ответ

0 голосов
/ 23 сентября 2019

Ответ приходит от Дэвид Жакель Может ли жидкость для цикла содержать переменную страницы в Jekyll?


Вы можете использовать скобочные обозначения, как это:

{% for data in site.data.faq.[page.pagefaq] %}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...