feat: fetch meta tags from website route meta
This commit is contained in:
@@ -2,9 +2,9 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" href="{{ favicon or '/assets/lms/frontend/favicon.png' }}" />
|
<link rel="icon" href="{{ favicon }}" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>{{ title or "Frappe Learning" }}</title>
|
<title>{{ title }}</title>
|
||||||
<meta name="title" content="{{ meta.title }}" />
|
<meta name="title" content="{{ meta.title }}" />
|
||||||
<meta name="image" content="{{ meta.image }}" />
|
<meta name="image" content="{{ meta.image }}" />
|
||||||
<meta name="description" content="{{ meta.description }}" />
|
<meta name="description" content="{{ meta.description }}" />
|
||||||
@@ -30,8 +30,6 @@
|
|||||||
<div id="popovers"></div>
|
<div id="popovers"></div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.csrf_token = '{{ csrf_token }}'
|
|
||||||
window.setup_complete = '{{ setup_complete }}'
|
|
||||||
document.getElementById('seo-content').style.display = 'none';
|
document.getElementById('seo-content').style.display = 'none';
|
||||||
</script>
|
</script>
|
||||||
<script type="module" src="/src/main.js"></script>
|
<script type="module" src="/src/main.js"></script>
|
||||||
|
|||||||
133
lms/www/lms.py
133
lms/www/lms.py
@@ -10,22 +10,55 @@ no_cache = 1
|
|||||||
|
|
||||||
def get_context():
|
def get_context():
|
||||||
app_path = frappe.form_dict.get("app_path")
|
app_path = frappe.form_dict.get("app_path")
|
||||||
|
favicon = (
|
||||||
|
frappe.db.get_single_value("Website Settings", "favicon")
|
||||||
|
or "/assets/lms/frontend/favicon.png"
|
||||||
|
)
|
||||||
|
title = frappe.db.get_single_value("Website Settings", "app_name") or "Frappe Learning"
|
||||||
|
|
||||||
context = frappe._dict()
|
context = frappe._dict()
|
||||||
if app_path:
|
context.meta = get_meta(app_path, title, favicon)
|
||||||
context.meta = get_meta(app_path)
|
|
||||||
else:
|
|
||||||
context.meta = {}
|
|
||||||
capture("active_site", "lms")
|
capture("active_site", "lms")
|
||||||
context.favicon = frappe.db.get_single_value("Website Settings", "favicon")
|
context.title = title
|
||||||
context.title = frappe.db.get_single_value("Website Settings", "app_name")
|
context.favicon = favicon
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
def get_meta(app_path):
|
def get_meta(app_path, title, favicon):
|
||||||
|
meta = {}
|
||||||
|
if app_path:
|
||||||
|
meta = get_meta_from_document(app_path, favicon)
|
||||||
|
|
||||||
|
route_meta = frappe.get_all("Website Meta Tag", {"parent": app_path}, ["key", "value"])
|
||||||
|
|
||||||
|
if len(route_meta) > 0:
|
||||||
|
for row in route_meta:
|
||||||
|
if row.key == "title":
|
||||||
|
meta["title"] = row.value
|
||||||
|
elif row.key == "image":
|
||||||
|
meta["image"] = row.value
|
||||||
|
elif row.key == "description":
|
||||||
|
meta["description"] = f"{meta.get('description', '')} {row.value}"
|
||||||
|
elif row.key == "keywords":
|
||||||
|
meta["keywords"] = f"{meta.get('keywords', '')} {row.value}"
|
||||||
|
elif row.key == "link":
|
||||||
|
meta["link"] = row.value
|
||||||
|
|
||||||
|
if not meta:
|
||||||
|
meta = {
|
||||||
|
"title": title,
|
||||||
|
"image": favicon,
|
||||||
|
"description": "Easy to use Learning Management System",
|
||||||
|
}
|
||||||
|
|
||||||
|
return meta
|
||||||
|
|
||||||
|
|
||||||
|
def get_meta_from_document(app_path, favicon):
|
||||||
if app_path == "courses":
|
if app_path == "courses":
|
||||||
return {
|
return {
|
||||||
"title": _("Course List"),
|
"title": _("Course List"),
|
||||||
"image": frappe.db.get_single_value("Website Settings", "banner_image"),
|
"image": favicon,
|
||||||
"description": "This page lists all the courses published on our website",
|
"description": "This page lists all the courses published on our website",
|
||||||
"keywords": "All Courses, Courses, Learn",
|
"keywords": "All Courses, Courses, Learn",
|
||||||
"link": "/courses",
|
"link": "/courses",
|
||||||
@@ -47,6 +80,11 @@ def get_meta(app_path):
|
|||||||
["title", "image", "description", "tags"],
|
["title", "image", "description", "tags"],
|
||||||
as_dict=True,
|
as_dict=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if course.description:
|
||||||
|
soup = BeautifulSoup(course.description, "html.parser")
|
||||||
|
course.description = soup.get_text()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"title": course.title,
|
"title": course.title,
|
||||||
"image": course.image,
|
"image": course.image,
|
||||||
@@ -58,7 +96,7 @@ def get_meta(app_path):
|
|||||||
if app_path == "batches":
|
if app_path == "batches":
|
||||||
return {
|
return {
|
||||||
"title": _("Batches"),
|
"title": _("Batches"),
|
||||||
"image": frappe.db.get_single_value("Website Settings", "banner_image"),
|
"image": favicon,
|
||||||
"description": "This page lists all the batches published on our website",
|
"description": "This page lists all the batches published on our website",
|
||||||
"keywords": "All Batches, Batches, Learn",
|
"keywords": "All Batches, Batches, Learn",
|
||||||
"link": "/batches",
|
"link": "/batches",
|
||||||
@@ -71,6 +109,11 @@ def get_meta(app_path):
|
|||||||
["title", "meta_image", "batch_details", "category", "medium"],
|
["title", "meta_image", "batch_details", "category", "medium"],
|
||||||
as_dict=True,
|
as_dict=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if batch.batch_details:
|
||||||
|
soup = BeautifulSoup(batch.batch_details, "html.parser")
|
||||||
|
batch.batch_details = soup.get_text()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"title": batch.title,
|
"title": batch.title,
|
||||||
"image": batch.meta_image,
|
"image": batch.meta_image,
|
||||||
@@ -84,7 +127,7 @@ def get_meta(app_path):
|
|||||||
if "new/edit" in app_path:
|
if "new/edit" in app_path:
|
||||||
return {
|
return {
|
||||||
"title": _("New Batch"),
|
"title": _("New Batch"),
|
||||||
"image": frappe.db.get_single_value("Website Settings", "banner_image"),
|
"image": favicon,
|
||||||
"description": "Create a new batch",
|
"description": "Create a new batch",
|
||||||
"keywords": "New Batch, Create Batch",
|
"keywords": "New Batch, Create Batch",
|
||||||
"link": "/lms/batches/new/edit",
|
"link": "/lms/batches/new/edit",
|
||||||
@@ -95,6 +138,11 @@ def get_meta(app_path):
|
|||||||
["title", "meta_image", "batch_details", "category", "medium"],
|
["title", "meta_image", "batch_details", "category", "medium"],
|
||||||
as_dict=True,
|
as_dict=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if batch.batch_details:
|
||||||
|
soup = BeautifulSoup(batch.batch_details, "html.parser")
|
||||||
|
batch.batch_details = soup.get_text()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"title": batch.title,
|
"title": batch.title,
|
||||||
"image": batch.meta_image,
|
"image": batch.meta_image,
|
||||||
@@ -106,7 +154,7 @@ def get_meta(app_path):
|
|||||||
if app_path == "job-openings":
|
if app_path == "job-openings":
|
||||||
return {
|
return {
|
||||||
"title": _("Job Openings"),
|
"title": _("Job Openings"),
|
||||||
"image": frappe.db.get_single_value("Website Settings", "banner_image"),
|
"image": favicon,
|
||||||
"description": "This page lists all the job openings published on our website",
|
"description": "This page lists all the job openings published on our website",
|
||||||
"keywords": "Job Openings, Jobs, Vacancies",
|
"keywords": "Job Openings, Jobs, Vacancies",
|
||||||
"link": "/job-openings",
|
"link": "/job-openings",
|
||||||
@@ -131,7 +179,7 @@ def get_meta(app_path):
|
|||||||
if app_path == "statistics":
|
if app_path == "statistics":
|
||||||
return {
|
return {
|
||||||
"title": _("Statistics"),
|
"title": _("Statistics"),
|
||||||
"image": frappe.db.get_single_value("Website Settings", "banner_image"),
|
"image": favicon,
|
||||||
"description": "This page lists all the statistics of this platform",
|
"description": "This page lists all the statistics of this platform",
|
||||||
"keywords": "Enrollment Count, Completion, Signups",
|
"keywords": "Enrollment Count, Completion, Signups",
|
||||||
"link": "/statistics",
|
"link": "/statistics",
|
||||||
@@ -176,3 +224,64 @@ def get_meta(app_path):
|
|||||||
"keywords": f"{badge.title}, {badge.description}",
|
"keywords": f"{badge.title}, {badge.description}",
|
||||||
"link": f"/badges/{badgeName}/{email}",
|
"link": f"/badges/{badgeName}/{email}",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if app_path == "quizzes":
|
||||||
|
return {
|
||||||
|
"title": _("Quizzes"),
|
||||||
|
"image": favicon,
|
||||||
|
"description": _("Test your knowledge with interactive quizzes and more."),
|
||||||
|
"keywords": "Quizzes, interactive quizzes, online quizzes",
|
||||||
|
"link": "/quizzes",
|
||||||
|
}
|
||||||
|
|
||||||
|
if re.match(r"^quizzes/[^/]+$", app_path):
|
||||||
|
quiz_name = app_path.split("/")[1]
|
||||||
|
quiz = frappe.db.get_value(
|
||||||
|
"LMS Quiz",
|
||||||
|
quiz_name,
|
||||||
|
["title"],
|
||||||
|
as_dict=True,
|
||||||
|
)
|
||||||
|
if quiz:
|
||||||
|
return {
|
||||||
|
"title": quiz.title,
|
||||||
|
"image": favicon,
|
||||||
|
"description": "Test your knowledge with interactive quizzes.",
|
||||||
|
"keywords": quiz.title,
|
||||||
|
"link": f"/quizzes/{quiz_name}",
|
||||||
|
}
|
||||||
|
|
||||||
|
if app_path == "assignments":
|
||||||
|
return {
|
||||||
|
"title": _("Assignments"),
|
||||||
|
"image": favicon,
|
||||||
|
"description": _("Test your knowledge with interactive assignments and more."),
|
||||||
|
"keywords": "Assignments, interactive assignments, online assignments",
|
||||||
|
"link": "/assignments",
|
||||||
|
}
|
||||||
|
|
||||||
|
if re.match(r"^assignments/[^/]+$", app_path):
|
||||||
|
assignment_name = app_path.split("/")[1]
|
||||||
|
assignment = frappe.db.get_value(
|
||||||
|
"LMS Assignment",
|
||||||
|
assignment_name,
|
||||||
|
["title"],
|
||||||
|
as_dict=True,
|
||||||
|
)
|
||||||
|
if assignment:
|
||||||
|
return {
|
||||||
|
"title": assignment.title,
|
||||||
|
"image": favicon,
|
||||||
|
"description": "Test your knowledge with interactive assignments.",
|
||||||
|
"keywords": assignment.title,
|
||||||
|
"link": f"/assignments/{assignment_name}",
|
||||||
|
}
|
||||||
|
|
||||||
|
if app_path == "programs":
|
||||||
|
return {
|
||||||
|
"title": _("Programs"),
|
||||||
|
"image": favicon,
|
||||||
|
"description": "This page lists all the programs published on our website",
|
||||||
|
"keywords": "All Programs, Programs, Learn",
|
||||||
|
"link": "/programs",
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user