Skip to content
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

Umieszczanie Linked Data w stopce wygenerowanej strony #890

Open
AdamWalkowski opened this issue Jan 13, 2024 · 0 comments
Open

Umieszczanie Linked Data w stopce wygenerowanej strony #890

AdamWalkowski opened this issue Jan 13, 2024 · 0 comments
Labels
SEO Pola scores visible in Google search results

Comments

@AdamWalkowski
Copy link
Member

AdamWalkowski commented Jan 13, 2024

CONTEXT
Aby Google zaindeksował wyniki firm w rankigu poli, potrzeba date { firma, wynik } zapisać w formacie JSON-LD (np. jako FAQ: pytanie - odpowiedź) i umieścić tak sformatowaną treść w stopce wygenerowanego pliku HTML.

Gatsby generuje strony HTML w trakcie budowania aplikacji. Czyli optymalne byłoby pobranie wyników wszystkich firm z API jednorazowo w trakcie budowania. Czyli te dane nie zmieniałyby się póki nie zmieni się wersja aplikacji web.

W stopce strony HTML można umieszczać treść za pomocą React Helmet.

IMPLEMENTATION

const axios = require('axios');
const path = require('path');

exports.createPages = async ({ actions: { createPage } }) => {
  const result = await axios.get('api.pola.pl/companies');
  const companies = result.data;

  faqs.forEach(faq => {
    createPage({
      path: `/hidden}`,
      component: path.resolve('./src/templates/hiddenPageTemplate.js'),
      context: {
        companies
      },
    });
  });
};

HIDDEN PAGE TEMPLATE

import React from 'react';
import { Helmet } from 'react-helmet';

const ScoresPage = ({ pageContext: { companies } }) => {

  const generateStructuredData = (companies) => {
    return {
      "@context": "https://schema.org",
      "@type": "FAQPage",
      "mainEntity": companies.map(company => ({
        "@type": "Question",
        "name": generateQuestion(company),
        "acceptedAnswer": {
          "@type": "Answer",
          "text": generateAnswer(company)
        }
      }))
    };
  };

  return (
    <div>
      <Helmet>
        <script type="application/ld+json">
          {JSON.stringify(generateStructuredData(companies))}
        </script>
      </Helmet>
      {faqs.map(company=> (
        <div key={faq.id}>
          <h2>{faq.question}</h2>
          <p>{faq.answer}</p>
        </div>
      ))}
    </div>
  );
};

export default ScoresPage;
@AdamWalkowski AdamWalkowski added the SEO Pola scores visible in Google search results label Jan 13, 2024
@MatPerowicz MatPerowicz moved this to Backlog in Pola-app 3.0 May 15, 2024
@github-project-automation github-project-automation bot moved this to Specified in Pola Web 1.0 Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SEO Pola scores visible in Google search results
Projects
Status: Specified
Status: Backlog
Development

No branches or pull requests

1 participant