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

Sitemaps dinâmicos #797

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions next-sitemap.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import('next-sitemap').IConfig} */
const config = {
siteUrl: 'https://tabnews.com.br',
generateRobotsTxt: true,
generateIndexSitemap: true,
sitemapSize: 7000,
robotsTxtOptions: {
additionalPaths: [`https://tabnews.com.br/sitemap.xml`],
},
};

module.exports = config;
51 changes: 47 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"joi": "17.6.3",
"next": "13.0.0",
"next-connect": "0.13.0",
"next-sitemap": "^3.1.29",
"node-pg-migrate": "6.2.2",
"nodemailer": "6.8.0",
"nprogress": "0.2.0",
Expand Down
24 changes: 24 additions & 0 deletions pages/sitemap.xml.public.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { getServerSideSitemap } from 'next-sitemap';

/** @type {import('next').GetServerSideProps} */
export async function getServerSideProps(ctx) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oi @r3nanp, muito legal essa contribuição!

Aí vão minhas dúvidas e considerações:

  • Será que faz sentido e daria para utilizar com páginas estáticas usando getStaticProps?
  • Se eu entendi direito, está adicionando somente os 30 conteúdos da primeira página de relevantes. Será que isso não vai prejudicar o SEO ao invés de ajudar? Seria legal adicionar bem mais conteúdos. Além de adicionar as outras páginas que não são conteúdos.
  • Você está passando content.slug como loc. Será que o correto não seria passar `/${content.owner_username}/${content.slug}`?
  • O formato da data que está sendo passada para lastmod está correto? Só estou perguntando por desencargo, pois eu não verifiquei.
  • Deixe fixa a versão das bibliotecas utilizadas: "next-sitemap": "3.1.29"

Bom trabalho!

const response = await fetch('/api/v1/contents');
const allContents = await response.json();

const fields = allContents.map((content) => {
/** @type {import('next-sitemap').ISitemapField} */
const field = {
loc: content.slug,
lastmod: content.updated_at,
};

return field;
});

return getServerSideSitemap(ctx, fields);
}

export default function Sitemap() {
// Just an empty page to generate the sitemap content via getServerSideProps
return null;
}