Skip to content

Sitemap generator including newsletters - #476

Open
elcreator wants to merge 3 commits into
BeWelcome:developfrom
elcreator:feature/sitemap-generation
Open

Sitemap generator including newsletters#476
elcreator wants to merge 3 commits into
BeWelcome:developfrom
elcreator:feature/sitemap-generation

Conversation

@elcreator

Copy link
Copy Markdown
Contributor

Files Created

1. config/sitemap.yaml - Sitemap Configuration

This YAML file contains:

  • Static routes with their paths and priorities (home, signup, about, terms, etc.)

  • Dynamic routes configuration with priorities for:

    • faq_categories (0.6) - FAQ categories from database
    • newsletters (0.6) - Newsletter articles with language variants

2. src/Command/GenerateSitemapCommand.php - Console Command

A Symfony console command that:

  • Reads configuration from config/sitemap.yaml
  • Generates static URLs from config with configured priorities
  • Queries database for all published newsletters (status='Triggered', type='Normal')
  • For each newsletter, finds all available language translations and generates URLs like /newsletters/121/en
  • Queries database for all FAQ categories and generates URLs like /faq/1, /faq/2, etc.
  • Outputs proper sitemap XML with <loc>, <lastmod>, and <priority> elements
  • Writes to public/sitemap.xml

Usage

php bin/console sitemap:generate

Optional base URL override:

php bin/console sitemap:generate --base-url=https://www.bewelcome.org

Example Output URLs

  • Static: https://www.bewelcome.org/, /about, /signup, etc.
  • FAQ: https://www.bewelcome.org/faq/1, /faq/2, /faq/3, etc.
  • Newsletters: https://www.bewelcome.org/newsletters/121/en, /newsletters/121/de, etc.

Note: Testing requires PHP 8.4+ (project requirement). The command follows Symfony conventions with auto-discovery via #[AsCommand] attribute.

@elcreator
elcreator force-pushed the feature/sitemap-generation branch 2 times, most recently from 1fa2958 to af9946b Compare August 9, 2026 15:08
@elcreator
elcreator force-pushed the feature/sitemap-generation branch 2 times, most recently from 670ea76 to f709c7c Compare August 9, 2026 16:06
@elcreator
elcreator force-pushed the feature/sitemap-generation branch from f709c7c to 072b2d6 Compare August 9, 2026 16:09
Comment thread src/Command/GenerateSitemapCommand.php Outdated
// Last modified
$xml->startElement('lastmod');
$lastmod = $urlData['lastmod'];
if ($lastmod instanceof \Carbon\Carbon) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be Carbon only (simplify FQDn with use Carbon\Carbon.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs a cron job, doesn't it? Or is the expectation to just run it from time to time?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It can be either a cron i.e. once per week, per month or manual run after newsletter publish.
Currently it is intended to fix at least current sitemap misleading the search engines that site got last content update 2020-05-17.

Comment thread config/sitemap.yaml Outdated
priority: 0.6
newsletters:
# Newsletter articles with language variants
priority: 0.6 No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing new line at the end of file.


return $xml->outputMemory(true);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing new line at the end of file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

shouldn't it be added to phpcbf? I may do this in this PR or separately,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That wouldn't help for the yaml files. Git complains about that the time if you do not add one...

Comment thread composer.json
"ext-pdo": "*",
"ext-pdo_mysql": "*",
"ext-session": "*",
"ext-xmlwriter": "*",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The docker setup like needs to be adapted as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

https://www.php.net/manual/en/xmlwriter.installation.php The XMLWriter ships with PHP and is enabled by default. It is rather cosmetic change so IDEs can consistently highlight imports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants