How to create multiple sitemap types in Drupal - drupal-8

I want to create multiple sitemap type for node, taxonomy in Drupal 8/9
For example
1 sitemap for "Article" content type
Like: example.com/article-sitemap.xml
1 sitemap for "Basic page" content type
Like: example.com/page-sitemap.xml
1 sitemap for "News" content page
Like: example.com/news-sitemap.xml
And list all this sitemap in sitemap.xml
I tried with different module but didn't get any result I want
Please help me with this

The Simple XML Sitemap module can do it out of the box.
After installing,
Go to /admin/config/search/simplesitemap and create your sitemaps. Name them according to your content types/taxonomies and make sure they are of the default hreflang sitemap type.
Enable the sitemap index by editing it and changing its status. If it's not been created for you, you can create it manually by creating a sitemap of the index type.
Navigate to /admin/config/search/simplesitemap/settings and set the default sitemap to be the sitemap index. This way the index of your sitemaps will be available under /sitemap.xml.
Navigate to /admin/config/search/simplesitemap/entities and set content/taxonomy types to be included in the specific sitemaps you created.
Go back to /admin/config/search/simple_sitemap and click on 'rebuild queue & generate'.
Check the results by visiting /sitemap.xml.

Related

Save the dynamically populated value on dropdown

I'm using wagtail CMS for Django, I want to add a dynamically populated value for a dropdown and save it on the Page model, this is my code:
class MyPage(Page):
domain = CharField(max_length=10, choices=MY_CHOICES)
subdomain = CharField(max_length=10, choices=[('', '------')]
I've got some frontend logic to populate dynamically the options for subdomain, but after I hit save I got: The page could not be created due to validation errors And in the subdomain field: Select a valid choice. [my value] is not one of the available choices.
I can't use ForeignKey to populate subdomain because it depends from an external API service that we're using.
I tried to use a custom field that inherits from CharField with no success, it looks it executes validate method only for the domain field.
If you use the choices argument, you have to predefine the list of possible values. Read the relevant part of the docs (last two paragraphs of that section).
You could omit the choices argument from the model field definition and only render a HTML select tag in the frontend (which is then filled with options dynamically, like you explained).
You could also look into changing the default widget of the CharField to a select tag, like this answer and this part of the docs show.

django dynamic scraper range_funct pagination

I am using django-dynamic-scraper in one of my applications, I have gone through the docs and following is my setup:
object class url I am using is : http://www.example.com/products/brandname_products.html
The pagination on the site is something like the following.
page 1: http://www.example.com/products/brandname_products.html
page 2: http://www.example.com/products/brandname_products2.html
page 3: http://www.example.com/products/brandname_products3.html
page 4: http://www.example.com/products/brandname_products4.html
The brandname in the above urls is dynamic and depends on a brand's products page. I cannot have a different scraper for each brand as there are over 10000 brands so I am trying to use a single scraper object.
In the scraper object that I am using I have defined the pagination options as follows:
pagination_type: RANGE_FUNCT
pagination_append_str: _products{page}.html
pagination_page_replace: 1,100,2
but the scraper requests the following pagination urls
http://www.example.com/products/brandname_products.html_products2.html
http://www.example.com/products/brandname_products.html_products3.html
http://www.example.com/products/brandname_products.html_products4.html
Instead of
http://www.example.com/products/brandname_products2.html
http://www.example.com/products/brandname_products3.html
http://www.example.com/products/brandname_products4.html
Q: Why is it appending the replace string to the end of the url instead of actually replacing it with _products.html in the object class url ? What am I doing wrong and how can I fix this.
The pagination_append_str option is called like this, because the string is appended to the base url and not replacing it! :-)
So everything is correct, you just have to remove _products_html from your base url so that the final url is build together without doubling url parts.

Django pagination - nice urls

I did pagination in my django projet. Everything works just perfect, but my urls looks terrible, like
host:8000/?page=1
How to create nice urls like
host:8000/page/2/ or host:8000/2/
I use standard Paginator class via ListView
How to do this w/o third party code ?
If you define url pattern like this:
url(r'^/page/(?P<page>\d+)/$', 'myapp.views.list_view'),
then ListView will pass page url keyword into paginator.
Notice:
Each path segment is supposed to be a valid resource, so it's not clear what you will display on /path/ URL.
Django pagination system assumes that webpages will default to using the URL query, so it's recommended to keep it as a URL query and it's more revealing.

How to add a custom template page to mezzanine?

I've been playing around with mezzanine for a couple days and I've been following this blog, which has been very helpful.
I'm now at the point where I need to make a bunch of pages that need to be based off of a custom template. My custom template is called content.html
I've put it in myProject > myApp/theme folder > templates > pages > content.html but when I look in the admin console, I don't see content in the drop down menu.
How do I get mezzanine to recognize my content.html page as a template?
content.html will not automatically appear in your site's drop down menu.
You need to go to the admin site and explicitly declare a page my content where you would like content.html to appear in your page hierarchy.
For mezzanine to match the two (i.e. template content.html and admin page my content):
Either my content's Title field (in admin site) should be content,
Or, URL field (in the meta data section of my content) should be content (if you decide the title will not be content),
Or, if you want content.html to have a custom slug, say nicecontent, then fill URL field with nicecontent and add to url.py a pattern for content.html with a matching slug, so:
url("^nicecontent/$", direct_to_template, {"template": "path/to/content.html"}, name="name_for_content").
There's a method Mezzanine uses for looking up template names, from the broadest ("page.html", which all other templates also extend), to templates named for their content types (richtextpage.html, gallery.html, etc), down to the most granular level, which is templates matching the url/slug of individual pages.
This is all covered in the documentation:
http://mezzanine.jupo.org/docs/content-architecture.html#page-templates
It sounds like you might be looking for "page.html", but it's not clear from your question.

Django: Pagination with urls.py

I'm building a Blog in Django (using Generic Views) and I use the same template for both my date based and list detail views. I'm trying to setup pagination, but I want to do so with URL patterns rather than using an ugly ?page=1 url suffix.
The problem is in the actual html template, I cannot find a way to determine which view was used to render the page, so while I have access to all the pagination stuff, I have no way to generate the appropriate URL.
In other words, if the view was rendered by my archive_month(request, month, year, page=0) view, I would need to structure the URL for the next and previous pages as /blog/dec/2009/PageX/, versus the blog index, which would mean the URL would be /blog/pageX/.
Well I just realized that date_based generic views don't support pagination, so problem solved.