How to do it...

Follow these steps to add a book's page to sitemap.xml:

  1. Import the given methods in main.py, as follows:
    from odoo.addons.http_routing.models.ir_http import slug
    from odoo.addons.website.models.ir_http import sitemap_qs2dom
  2. Add the sitemap_books method in the main.py, as follows:
    class Main(http.Controller):
    ...
    def sitemap_books(env, rule, qs):
    Books = env['library.book']
    dom = sitemap_qs2dom(qs, '/books', Books._rec_name)
    for f in Books.search(dom):
    loc = '/books/%s' % slug(f)
    if not qs or qs.lower() in loc:
    yield {'loc': loc}
    ...
  3. Add the sitemap_books function reference in a book's detail routes as follows:
    ...
    @http.route('/books/<model("library.book"):book>', type='http', auth="user", website=True, sitemap=sitemap_books)
    def library_book_detail(self, book):
    ...

Update the module to apply the changes. The sitemap.xml file is generated and stored in attachments. Then, it is regenerated every few hours. To see our changes, you will need to remove the sitemap file from the attachment. To do this, visit Settings|Technical|Database Structure|Attachments, search for the sitemap, and delete the file. Now, access the /sitemap.xml URL in a browser, and you will see the book's pages in the sitemap.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset