qumra-engine 2.0.53 → 2.0.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extensions/logic/seo.js +84 -26
- package/package.json +1 -1
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const nunjucks_1 = require("nunjucks");
|
|
4
|
+
const escapeAttr = (str) => String(str ?? "")
|
|
5
|
+
.replace(/&/g, "&")
|
|
6
|
+
.replace(/</g, "<")
|
|
7
|
+
.replace(/>/g, ">")
|
|
8
|
+
.replace(/"/g, """)
|
|
9
|
+
.replace(/'/g, "'");
|
|
10
|
+
const textOnly = (str, limit = 160) => {
|
|
11
|
+
const s = String(str ?? "")
|
|
12
|
+
.replace(/<[^>]*>/g, "") // شيل أي HTML
|
|
13
|
+
.replace(/\s+/g, " ") // سطر واحد
|
|
14
|
+
.trim();
|
|
15
|
+
return limit > 0 && s.length > limit ? s.slice(0, limit - 1).trim() + "…" : s;
|
|
16
|
+
};
|
|
17
|
+
const safeUrl = (str) => {
|
|
18
|
+
const s = String(str ?? "").trim();
|
|
19
|
+
if (!s)
|
|
20
|
+
return "";
|
|
21
|
+
if (/^https?:\/\//i.test(s))
|
|
22
|
+
return s;
|
|
23
|
+
if (s.startsWith("/"))
|
|
24
|
+
return s; // مسار داخلي
|
|
25
|
+
return ""; // غير مسموح
|
|
26
|
+
};
|
|
4
27
|
exports.default = new (class SeoExtension {
|
|
5
28
|
constructor() {
|
|
6
29
|
this.tags = ["seo"];
|
|
@@ -11,31 +34,66 @@ exports.default = new (class SeoExtension {
|
|
|
11
34
|
return new nodes.CallExtension(this, "run", null);
|
|
12
35
|
}
|
|
13
36
|
run({ ctx }) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const favicon = seo.logo || "/favicon.ico";
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const c = ctx.context || {};
|
|
38
|
+
const seo = c.seo || {};
|
|
39
|
+
const page = c.page || {};
|
|
40
|
+
const store = c.store || {};
|
|
41
|
+
// قيم أساسية
|
|
42
|
+
const siteName = store?.name || "Store";
|
|
43
|
+
const titleRaw = seo.title || page.title || siteName;
|
|
44
|
+
const descRaw = seo.description || page.description || "";
|
|
45
|
+
const pageTitle = textOnly(titleRaw, 70); // يفضّل ≤ 60–70
|
|
46
|
+
const pageDesc = textOnly(descRaw, 160);
|
|
47
|
+
const canonical = safeUrl(seo.canonical || page.canonical || "");
|
|
48
|
+
const ogImage = safeUrl(seo.image || page.image || "");
|
|
49
|
+
const favicon = safeUrl(seo.logo || "/favicon.ico");
|
|
50
|
+
const noindex = !!seo.noindex;
|
|
51
|
+
// بناء الوسوم
|
|
52
|
+
const parts = [];
|
|
53
|
+
// Title
|
|
54
|
+
parts.push(`<title>${escapeAttr(pageTitle)}</title>`);
|
|
55
|
+
// Canonical
|
|
56
|
+
if (canonical)
|
|
57
|
+
parts.push(`<link rel="canonical" href="${escapeAttr(canonical)}">`);
|
|
58
|
+
// Favicon
|
|
59
|
+
if (favicon) {
|
|
60
|
+
parts.push(`<link rel="icon" href="${escapeAttr(favicon)}">`);
|
|
61
|
+
parts.push(`<link rel="shortcut icon" href="${escapeAttr(favicon)}">`);
|
|
62
|
+
}
|
|
63
|
+
// Meta description
|
|
64
|
+
if (pageDesc)
|
|
65
|
+
parts.push(`<meta name="description" content="${escapeAttr(pageDesc)}">`);
|
|
66
|
+
// Robots
|
|
67
|
+
if (noindex) {
|
|
68
|
+
parts.push(`<meta name="robots" content="noindex, nofollow">`);
|
|
69
|
+
parts.push(`<meta property="og:robots" content="noindex, nofollow">`);
|
|
70
|
+
}
|
|
71
|
+
// Open Graph
|
|
72
|
+
parts.push(`<meta property="og:type" content="website">`);
|
|
73
|
+
parts.push(`<meta property="og:title" content="${escapeAttr(pageTitle)}">`);
|
|
74
|
+
if (pageDesc)
|
|
75
|
+
parts.push(`<meta property="og:description" content="${escapeAttr(pageDesc)}">`);
|
|
76
|
+
if (canonical)
|
|
77
|
+
parts.push(`<meta property="og:url" content="${escapeAttr(canonical)}">`);
|
|
78
|
+
if (siteName)
|
|
79
|
+
parts.push(`<meta property="og:site_name" content="${escapeAttr(siteName)}">`);
|
|
80
|
+
if (ogImage)
|
|
81
|
+
parts.push(`<meta property="og:image" content="${escapeAttr(ogImage)}">`);
|
|
82
|
+
// Twitter
|
|
83
|
+
parts.push(`<meta name="twitter:card" content="${ogImage ? "summary_large_image" : "summary"}">`);
|
|
84
|
+
parts.push(`<meta name="twitter:title" content="${escapeAttr(pageTitle)}">`);
|
|
85
|
+
if (pageDesc)
|
|
86
|
+
parts.push(`<meta name="twitter:description" content="${escapeAttr(pageDesc)}">`);
|
|
87
|
+
if (ogImage)
|
|
88
|
+
parts.push(`<meta name="twitter:image" content="${escapeAttr(ogImage)}">`);
|
|
89
|
+
// Itemprop (Google)
|
|
90
|
+
parts.push(`<meta itemprop="name" content="${escapeAttr(pageTitle)}">`);
|
|
91
|
+
if (pageDesc)
|
|
92
|
+
parts.push(`<meta itemprop="description" content="${escapeAttr(pageDesc)}">`);
|
|
93
|
+
if (ogImage)
|
|
94
|
+
parts.push(`<meta itemprop="image" content="${escapeAttr(ogImage)}">`);
|
|
95
|
+
// إخراج منظّف
|
|
96
|
+
const html = parts.join("\n");
|
|
97
|
+
return new nunjucks_1.runtime.SafeString(html);
|
|
40
98
|
}
|
|
41
99
|
})();
|