Comments

hmartens@gmail.com created an issue. See original summary.

gbyte’s picture

Status: Active » Postponed (maintainer needs more info)

Have you tried going to admin/config/search/simplesitemap and checking the checkbox Skip non-existent translations?

hmartens’s picture

Hi, yes i did. I don't know if it's the right approach but I went into Languages and deleted English and now the /en is gone but I do not know if some of my content was deleted ;)

hmartens’s picture

It would be awesome if there were a tick box to select what languages you want in your sitemap. Or perhaps an exclude field where you can add paths to exclude?

Thank you for a great module!

ziomizar’s picture

Category: Support request » Feature request
Status: Postponed (maintainer needs more info) » Needs review

Maybe we can change this in a feature request?
IMHO we need this functionality at least for the home page and views.

Scenario:
- I have two languages on my website english and german.
- Default language is german but i also have some pages ready to be published in english.
- I have 3 views : posts, jobs, news
- In my sitemap custom path i have to add : /, /post, /jobs and /news because these paths are not added automatically.

Sitemap.xml return:
- /post, /post/en
- /jobs, /jobs/en
- /news, /news/en
- /, /en

Also if the translation of views don't have results and is not listed into the custom links.

Would be great have a textarea identical to "custom links" where we can write "excluded links".
In this way in our scenario we can write in "excluded links" textarea:
- /jobs/en
- /post/en
- /news/en
- /en
To have a correct sitemaps.

gbyte’s picture

Version: 8.x-2.9 » 8.x-2.x-dev
Status: Needs review » Active

Where do you see the benefit of the sitemap not showing all language combinations for homepage or other non-entity pages? I think the better approach is to make the non-entity pages indexed with all languages (current implementation). If the site is not meant to be shown in another language, that language should not be there in the first place.

gbyte’s picture

Title: how to remove translation pages » Exclude translation variants for non-entity pages
ziomizar’s picture

Version: 8.x-2.x-dev » 8.x-2.9
Status: Active » Needs review

I agree with you and developer side would be better don't have unused languages.

Anyway i see a benefit just when we are preparing a new language for a website that is not ready yet in this language.
Content editor already filled up contents but all these are unpublished.

When your approach is perfect for entity like content types and taxonomy we still have issues with frontpage and views that listing into sitemap translations that doesn't exists or are unpublished (so in these language are empty for example).

We are using now hook_simple_sitemap_links_alter to hide these links, but would be great don't write code to do that.

ziomizar’s picture

Version: 8.x-2.9 » 8.x-2.x-dev
Status: Needs review » Active
maacl’s picture

Same as @ziomizar, we currently have two incomplete filled languages. First, because it takes time to get everything ready, and second we need approval from the client. So currently the language is blocked via htacess and robots.txt, to avoid indexing. It would be a nice feature to add a language to the sitemap when everything is ready.

gbyte’s picture

I am still not convinced this is a needed feature. I don't believe there is any harm in the sitemap pointing to non-translated content. If there is, please correct me. Worst case, there is always a hook you can use. Feel free however to submit a patch with the required changes, I will be more than happy to review it.

zebda’s picture

I'm having the same problem. The thing is the site is live in Dutch at the moment and is going to be in English soon till then I don't want the /en in my sitemap. I see there is not going to be a definite fix for this but how can I write a hook to hide the /en links? I see there is this: hook_simple_sitemap_links_alter but how can I use it?

gbyte’s picture

@zebda I've just updated the module's documentation pages with an example, please take a look.

@others Will gladly review/commit patches for this.

ziomizar’s picture

Status: Active » Needs review
StatusFileSize
new8.36 KB

This patch add a new tab "Disabled languages" on the simple sitemap settings.
Not sure if better add a textarea to exclude custom links, and call the whole section something like "Exclude".

gbyte’s picture

Status: Needs review » Needs work

Thanks for the patch. Looking through it, I would change a couple of things:

UI:

  • Include the setting on the main settings page under 'advanced settings'.
  • Setting should be a dropdown and be called 'Include languages' and contain the choice 'all' as first element. This will be more understandable to users. Still the module should save excluded languages to configuration.

Code:

  • simple_sitemap.settings.yml: Add excluded_languages: []
  • simple_sitemap.schema.yml: Rename 'disabled_languages' to 'excluded_languages'
  • We should act on disabling/deleting a language by removing it from simple_sitemap's excluded_languages setting.
  • SitemapGenerator.php 319: Use dependency injection
  • In Simplesitemap::addDisabledLanguage() you are saving to simple_sitemap.disabled_languages, yet according to simple_sitemap.schema.yml this setting is saved in simple_sitemap.settings

Regarding your question, why would you want to exclude custom links?

Looking forward to the improvements.

ziomizar’s picture

StatusFileSize
new6.89 KB
new9.97 KB

Moving the settings into the Advanced settings section indeed simplify a lot the code, i've removed lot of stuff using the Settings form.

I'm not sure about to use a dropdown for this setting, as i want for sure select one or more languages, but not necessarily all of them.

All the points in Code section should be fixed, but I can't see how to use properly dependence injection in SitemapGenerator.php 319. I can't put the service in the simple_sitemap.services.yml because the circular reference. Should I call the setGenerator method in Batch.php finishGeneration()?

ziomizar’s picture

Status: Needs work » Needs review
ziomizar’s picture

StatusFileSize
new6.28 KB
new624 bytes

Removed unused router to the old form

gbyte’s picture

Status: Needs review » Needs work

I'm not sure about to use a dropdown for this setting, as i want for sure select one or more languages, but not necessarily all of them.

I was thinking dropdown with multiple choice. I know this is more code to convert 'inluded languages' in the UI to 'excluded languages' storage and I am not sure if it is worth it. I think it is not that important, the UI part we can change any time.

I can't see how to use properly dependence injection in SitemapGenerator.php 319

You don't need to, the generator service is already injected, just use it:

  /**
   * @var \Drupal\simple_sitemap\Simplesitemap
   */
  protected $generator;

Have you found a way to react on language delete events?

Now that excluded_languages is in simple_sitemap.settings, we can use the simple_sitemap API method to get and set it, so instead of getExcludedLanguages(), just use simple_sitemap.generator service's getSetting('excluded_languages').

What are your thoughts?

ziomizar’s picture

Status: Needs work » Needs review
StatusFileSize
new3.62 KB
new7.34 KB

Agree, lets discuss about UI later.

When the sitemap generation run by Batch, $generator is not available, it is not defined by the constructor but using the setGenerator() method.

The cleanest way i saw until now to use it when Batch run, is

+        $generator = \Drupal::service('simple_sitemap.generator');
         \Drupal::service('simple_sitemap.sitemap_generator')
+          ->setGenerator($generator)
           ->generateSitemap($results['generate'], $remove_sitemap);

Good point about fire the deletion of a language. I've implemented hook_ENTITY_TYPE_delete() for 'configurable_language' and it works correctly. At the moment i'm just deleting the language from the settings and not regenerate the sitemap.

gbyte’s picture

StatusFileSize
new8.13 KB
new7.38 KB

Thanks for following up ziomizar.

I have made the following changes:

  • reverting the SitemapGenerator back and implementing the logic into UrlGeneratorBase::addUrlVariants(), as it does not make much sense to let this method generate all language links to then remove them in SitemapGenerator::generateSitemapChunk()
  • improving how the excluded languages are saved in configuration
  • loading languages with empty array as default
  • not allowing the user to exclude the default language
  • cleaning up the settings page
  • slightly improving the hook logic

Please review the patch for me.

gbyte’s picture

StatusFileSize
new10.43 KB
new9.95 KB

Screwed up the patch, here it goes again.

The last submitted patch, 21: exclude_languages-2875286-21.patch, failed testing. View results

  • gbyte.co committed 50b2be9 on 8.x-2.x
    Issue #2875286 by ziomizar: Exclude translation variants for non-entity...
gbyte’s picture

Status: Needs review » Fixed

No disagreement, so committing. Thanks @ziomizar.

ziomizar’s picture

Many thanks @gbyte!

Unfortunately havn't get time to work it more this week ;)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.