commit 807c4086021389b88a8cfe60880ac33448b9d361 Author: Ieva Date: Thu Nov 28 09:58:30 2024 +0200 initial commit diff --git a/sitemap_remove_url/__init__.py b/sitemap_remove_url/__init__.py new file mode 100644 index 0000000..c3d410e --- /dev/null +++ b/sitemap_remove_url/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import models +from . import controllers diff --git a/sitemap_remove_url/__manifest__.py b/sitemap_remove_url/__manifest__.py new file mode 100644 index 0000000..0845add --- /dev/null +++ b/sitemap_remove_url/__manifest__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +{ + 'name': 'Sitemap URL Remover', + 'description': 'This remove the unwanted urls from the sutemap url for website.', + 'summary': 'Remove URLs from the sitemap for better search engine indexing', + 'category': 'Website', + 'version': '14.0.0.1', + 'author': "Magnetposts.com", + 'company': 'Magnetposts.com', + 'maintainer': 'Magnetposts', + 'website': "https://www.magnetposts.com", + 'currency': 'USD', + 'category': 'Website', + 'depends': ['website'], + 'data': [ + 'security/ir.model.access.csv', + 'views/seo_seo_view.xml', + ], + 'images': [ + 'static/description/cover.gif', + ], + 'license': 'LGPL-3', + 'installable': True, + 'application': True, + 'auto_install': False, +} diff --git a/sitemap_remove_url/__pycache__/__init__.cpython-37.pyc b/sitemap_remove_url/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..2ccf9fd Binary files /dev/null and b/sitemap_remove_url/__pycache__/__init__.cpython-37.pyc differ diff --git a/sitemap_remove_url/controllers/__init__.py b/sitemap_remove_url/controllers/__init__.py new file mode 100644 index 0000000..12a7e52 --- /dev/null +++ b/sitemap_remove_url/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/sitemap_remove_url/controllers/__pycache__/__init__.cpython-37.pyc b/sitemap_remove_url/controllers/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..feb8637 Binary files /dev/null and b/sitemap_remove_url/controllers/__pycache__/__init__.cpython-37.pyc differ diff --git a/sitemap_remove_url/controllers/__pycache__/main.cpython-37.pyc b/sitemap_remove_url/controllers/__pycache__/main.cpython-37.pyc new file mode 100644 index 0000000..345aaed Binary files /dev/null and b/sitemap_remove_url/controllers/__pycache__/main.cpython-37.pyc differ diff --git a/sitemap_remove_url/controllers/main.py b/sitemap_remove_url/controllers/main.py new file mode 100644 index 0000000..14561e4 --- /dev/null +++ b/sitemap_remove_url/controllers/main.py @@ -0,0 +1,93 @@ +import logging +import datetime +import base64 +import copy + +from odoo import http, fields, _ +from odoo.http import request + +from odoo.addons.website.controllers.main import Website + +SITEMAP_CACHE_TIME = datetime.timedelta(hours=12) +LOC_PER_SITEMAP = 45000 + + +class WebsiteExtended(Website): + + @http.route('/sitemap.xml', type='http', auth="public", website=True, multilang=False, sitemap=False) + def sitemap_xml_index(self, **kwargs): + current_website = request.website + Attachment = request.env['ir.attachment'].sudo() + View = request.env['ir.ui.view'].sudo() + mimetype = 'application/xml;charset=utf-8' + content = None + + def create_sitemap(url, content): + return Attachment.create({ + 'raw': content.encode(), + 'mimetype': mimetype, + 'type': 'binary', + 'name': url, + 'url': url, + }) + dom = [('url', '=', '/sitemap-%d.xml' % current_website.id), ('type', '=', 'binary')] + sitemap = Attachment.search(dom, limit=1) + seos = request.env['seo.seo'].sudo().search([('is_indexed', '=', False)]) + if sitemap and not seos: + # Check if stored version is still valid + create_date = fields.Datetime.from_string(sitemap.create_date) + delta = datetime.datetime.now() - create_date + if delta < SITEMAP_CACHE_TIME: + content = base64.b64decode(sitemap.datas) + + if not content: + # Remove all sitemaps in ir.attachments as we're going to regenerated them + dom = [('type', '=', 'binary'), '|', ('url', '=like', '/sitemap-%d-%%.xml' % current_website.id), + ('url', '=', '/sitemap-%d.xml' % current_website.id)] + sitemaps = Attachment.search(dom) + sitemaps.unlink() + + pages = 0 + locs = request.website.with_user(request.website.user_id)._enumerate_pages() + locs = list(locs) + for rec in request.env['seo.seo'].sudo().search([]): + # for item in enumerate(locs): + # if rec.url_containing in item['loc']: + # del locs[n] + locs = [item for item in locs if rec.url_containing not in item['loc']] + rec.is_indexed = True + while True: + values = { + 'locs': locs, + 'url_root': request.httprequest.url_root[:-1], + } + urls = View._render_template('website.sitemap_locs', values) + if urls.strip(): + content = View._render_template('website.sitemap_xml', {'content': urls}) + pages += 1 + last_sitemap = create_sitemap('/sitemap-%d-%d.xml' % (current_website.id, pages), content) + if len(locs) * pages < LOC_PER_SITEMAP: + break + else: + break + + if not pages: + return request.not_found() + elif pages == 1: + # rename the -id-page.xml => -id.xml + last_sitemap.write({ + 'url': "/sitemap-%d.xml" % current_website.id, + 'name': "/sitemap-%d.xml" % current_website.id, + }) + else: + # TODO: in master/saas-15, move current_website_id in template directly + pages_with_website = ["%d-%d" % (current_website.id, p) for p in range(1, pages + 1)] + + # Sitemaps must be split in several smaller files with a sitemap index + content = View._render_template('website.sitemap_index_xml', { + 'pages': pages_with_website, + 'url_root': request.httprequest.url_root, + }) + create_sitemap('/sitemap-%d.xml' % current_website.id, content) + + return request.make_response(content, [('Content-Type', mimetype)]) diff --git a/sitemap_remove_url/models/__init__.py b/sitemap_remove_url/models/__init__.py new file mode 100644 index 0000000..21bf4a1 --- /dev/null +++ b/sitemap_remove_url/models/__init__.py @@ -0,0 +1 @@ +from . import seo_seo \ No newline at end of file diff --git a/sitemap_remove_url/models/__pycache__/__init__.cpython-37.pyc b/sitemap_remove_url/models/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..0d8268c Binary files /dev/null and b/sitemap_remove_url/models/__pycache__/__init__.cpython-37.pyc differ diff --git a/sitemap_remove_url/models/__pycache__/seo_seo.cpython-37.pyc b/sitemap_remove_url/models/__pycache__/seo_seo.cpython-37.pyc new file mode 100644 index 0000000..4ae0aaa Binary files /dev/null and b/sitemap_remove_url/models/__pycache__/seo_seo.cpython-37.pyc differ diff --git a/sitemap_remove_url/models/seo_seo.py b/sitemap_remove_url/models/seo_seo.py new file mode 100644 index 0000000..35c61fc --- /dev/null +++ b/sitemap_remove_url/models/seo_seo.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models + + +class SeoSeo(models.Model): + _name = 'seo.seo' + _rec_name = 'name' + + name = fields.Char('Name', required=True) + url_containing = fields.Char('URL containing') + is_indexed = fields.Boolean(default=False) diff --git a/sitemap_remove_url/security/ir.model.access.csv b/sitemap_remove_url/security/ir.model.access.csv new file mode 100644 index 0000000..7821214 --- /dev/null +++ b/sitemap_remove_url/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_seo_seo,seo.seo,model_seo_seo,base.group_system,1,1,1,1 diff --git a/sitemap_remove_url/static/description/cover.gif b/sitemap_remove_url/static/description/cover.gif new file mode 100644 index 0000000..168c539 Binary files /dev/null and b/sitemap_remove_url/static/description/cover.gif differ diff --git a/sitemap_remove_url/static/description/icon.png b/sitemap_remove_url/static/description/icon.png new file mode 100644 index 0000000..83cfae2 Binary files /dev/null and b/sitemap_remove_url/static/description/icon.png differ diff --git a/sitemap_remove_url/static/description/images/Image_01.png b/sitemap_remove_url/static/description/images/Image_01.png new file mode 100644 index 0000000..61cda9c Binary files /dev/null and b/sitemap_remove_url/static/description/images/Image_01.png differ diff --git a/sitemap_remove_url/static/description/images/Image_02.png b/sitemap_remove_url/static/description/images/Image_02.png new file mode 100644 index 0000000..d22d30d Binary files /dev/null and b/sitemap_remove_url/static/description/images/Image_02.png differ diff --git a/sitemap_remove_url/static/description/images/Image_03.png b/sitemap_remove_url/static/description/images/Image_03.png new file mode 100644 index 0000000..6b91a1c Binary files /dev/null and b/sitemap_remove_url/static/description/images/Image_03.png differ diff --git a/sitemap_remove_url/static/description/index.html b/sitemap_remove_url/static/description/index.html new file mode 100644 index 0000000..c64e5ad --- /dev/null +++ b/sitemap_remove_url/static/description/index.html @@ -0,0 +1,132 @@ +
+
+ +
+
+

+ This application removes the unwanted urls from the sitemap.xml file. That avoid unwanted server overloading by the search engine and other website crawlers. +

+
+
+ +
+
+ +

How it works?

+
+ +
+ +
+
+

Check unwanted urls

+

+ Open the /sitemap.xml url in your browser and check the unwanted URL's format. +

+
+
+ +
+
+ +
+
+ +
+
+

Create record for selected format

+

+ Go to website >> click on menu - Remove Sitemap URL >> Create a record (As shown in screenshot) +

+
+
+ +
+
+

Check sitemap URLs

+

+ Boom.. All urls removed from the sitemap. +

+
+
+ +
+
+ +

How to configure

+
+ +
+ +

+ Step 1 Download the module and place the module in apps folder. +

+ +

+ Step 2 + Install this module in your Odoo instance. + +

+ +

+ Step 3 Activate + developer mode. + and open settings. + +

+ +

+ Step 4 Go to Website >> Sitemap URL Remove >> Add records. + +

+ +

+ + DONE + That's it done. + +

+ +

Changelog

+
+ +
+ +
+
+

v14.0.0.1

+
+
+
NEW New extended module for v14.
+
+
+ +
+
+

Developed by Magnetposts

+
+ https://www.magnetposts.com +
+
+
+

Contact Us

+
+ contact@magnetposts.com +
+
+
\ No newline at end of file diff --git a/sitemap_remove_url/views/seo_seo_view.xml b/sitemap_remove_url/views/seo_seo_view.xml new file mode 100644 index 0000000..645f498 --- /dev/null +++ b/sitemap_remove_url/views/seo_seo_view.xml @@ -0,0 +1,45 @@ + + + + + seo.seo.list + seo.seo + + + + + + + + + + seo.seo.form + seo.seo + +
+ + + + + + + +
+
+
+ + + Seo Optimize + seo.seo + tree,form + + + + +
\ No newline at end of file