Parcourir la source

Merge pull request #16559 from frappe/sitemap-publish-condition

fix: sitemap condition
version-14
mergify[bot] il y a 3 ans
committed by GitHub
Parent
révision
fcb86d7f96
Aucune clé connue n'a été trouvée dans la base pour cette signature ID de la clé GPG: 4AEE18F83AFDEB23
1 fichiers modifiés avec 24 ajouts et 16 suppressions
  1. +24
    -16
      frappe/www/sitemap.py

+ 24
- 16
frappe/www/sitemap.py Voir le fichier

@@ -1,11 +1,11 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
# License: MIT. See LICENSE

from urllib.parse import quote

import frappe
from frappe.model.document import get_controller
from frappe.utils import get_datetime, get_url, nowdate
from frappe.utils import get_url, nowdate
from frappe.website.router import get_pages

no_cache = 1
@@ -14,13 +14,8 @@ base_template_path = "www/sitemap.xml"

def get_context(context):
"""generate the sitemap XML"""

# the site might be accessible from multiple host_names
# for e.g gadgets.erpnext.com and gadgetsinternational.com
# so it should be picked from the request
host = frappe.utils.get_host_name_from_request()

links = []

for route, page in get_pages().items():
if page.sitemap:
links.append({"loc": get_url(quote(page.name.encode("utf-8"))), "lastmod": nowdate()})
@@ -29,7 +24,7 @@ def get_context(context):
links.append(
{
"loc": get_url(quote((route or "").encode("utf-8"))),
"lastmod": get_datetime(data.get("modified")).strftime("%Y-%m-%d"),
"lastmod": f"{data['modified']:%Y-%m-%d}",
}
)

@@ -41,24 +36,37 @@ def get_public_pages_from_doctypes():

def get_sitemap_routes():
routes = {}
doctypes_with_web_view = [
d.name for d in frappe.db.get_all("DocType", {"has_web_view": 1, "allow_guest_to_view": 1})
]
doctypes_with_web_view = frappe.get_all(
"DocType",
filters={"has_web_view": True, "allow_guest_to_view": True},
pluck="name",
)

for doctype in doctypes_with_web_view:
controller = get_controller(doctype)
meta = frappe.get_meta(doctype)
condition_field = meta.is_published_field or controller.website.condition_field

try:
res = frappe.db.get_all(doctype, ["route", "name", "modified"], {condition_field: 1})
for r in res:
routes[r.route] = {"doctype": doctype, "name": r.name, "modified": r.modified}
if not condition_field:
continue

try:
res = frappe.get_all(
doctype,
fields=["route", "name", "modified"],
filters={condition_field: True},
)
except Exception as e:
if not frappe.db.is_missing_column(e):
raise e

for r in res:
routes[r.route] = {
"doctype": doctype,
"name": r.name,
"modified": r.modified,
}

return routes

return frappe.cache().get_value("sitemap_routes", get_sitemap_routes)

Chargement…
Annuler
Enregistrer