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

Make Default Target Directory Configurable #196

Open
kiler129 opened this issue Apr 19, 2019 · 6 comments
Open

Make Default Target Directory Configurable #196

kiler129 opened this issue Apr 19, 2019 · 6 comments

Comments

@kiler129
Copy link
Contributor

After #187 I realized that while output directory can be configured it produces a strange inconsistency: you get a sitemap in e.g. public/sitemap/xml/ while all your URLs are https://www.example.com/sitemap.foo_123.xml.gz in the index :)

I think we can solve this in two ways:

  • Allow configuration of the "public prefix" where you configure just the sitemap/xml/ part and the rest of the hard work is pulled from routing context
  • Simply allow putting a base URL in the config

While the second option is theoretically more flexible, IMHO the 1st one offers a better DX.

WDYT? I can offer a PR if you like :)

@yann-eugone
Copy link
Member

Did you had a look to the sitemap_file_prefix configuration entry ?

Maybe

presta_sitemap:
    sitemap_file_prefix: 'sitemap/xml/sitemap'

If it works, it is not a good DX, but we have to think about all cases :

  • dumped / not dumped sitemaps
  • standard / not standard places : public/foo/bar
  • standard / not standard sitemap names : notasitemap.xml

I have no idea about all cases, who are the people under each cases...

@kiler129
Copy link
Contributor Author

sitemap_file_prefix looks like a nice hack, but it doesn't work if you try to put a folder there ;)

Essentially you get Warning: file_put_contents(/tmp/PrestaSitemaps-5cba6206748c5/sitemap/sitemap.xml): failed to open stream: No such file or directory in dumper.

I will try to poke around this on Monday.

@NoodlesNZ
Copy link
Contributor

How did you get on with this? I just came across this issue when building a new site. I have our sitemaps under /sitemaps/, but the only way to fix the URLs in the sitemap index is to pass the full path into the dumper tool. It would be great if there was a configurable directory for the URLs.

@antonsnowy
Copy link

I've add to Dumper.php folder creation before file_put_contents()

$tmp = $this->tmpFolder . '/' . $this->sitemapFilePrefix;
$folder = substr($tmp, 0, strrpos($tmp, '/'));
if (!file_exists($folder)) {
    mkdir($folder, 0755, true);
}
file_put_contents($this->tmpFolder . '/' . $this->sitemapFilePrefix . '.xml', $this->getRoot()->toXml());

And add to config dump_directory: web/sitemaps and sitemap_file_prefix: 'sitemaps/sitemap'

Now I have sitemaps in web/sitemaps/sitemap.***.xml and index in web/sitemaps/sitemaps/sitemap.xml
It works, but you can do it right.

@pesseyjulien
Copy link

no solution yet ?

@yann-eugone
Copy link
Member

@pesseyjulien feel free to contribute if you need it quickly

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

No branches or pull requests

5 participants