@lynxflow/seo-engine 1.8.18 → 1.8.19
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/index.js +47 -0
- package/package.json +1 -1
- package/src/existing-media-harvester.ts +98 -0
- package/src/index.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -8076,6 +8076,52 @@ class PowerWordsPsychologyEngine {
|
|
|
8076
8076
|
return enriched;
|
|
8077
8077
|
}
|
|
8078
8078
|
}
|
|
8079
|
+
// packages/lynx-seo-engine/src/existing-media-harvester.ts
|
|
8080
|
+
class ExistingMediaHarvester {
|
|
8081
|
+
static harvestFromHtml(htmlContent, baseUrl = "") {
|
|
8082
|
+
const assets = [];
|
|
8083
|
+
const imgRegex = /<img\s+[^>]*src=["']([^"']+)["'][^>]*>/gi;
|
|
8084
|
+
const altRegex = /alt=["']([^"']*)["']/i;
|
|
8085
|
+
let match;
|
|
8086
|
+
const seenUrls = new Set;
|
|
8087
|
+
while ((match = imgRegex.exec(htmlContent)) !== null) {
|
|
8088
|
+
const fullImgTag = match[0];
|
|
8089
|
+
let src = match[1];
|
|
8090
|
+
if (src.includes("gravatar.com") || src.includes("icon-") || src.includes(".svg") || src.includes("1x1")) {
|
|
8091
|
+
continue;
|
|
8092
|
+
}
|
|
8093
|
+
if (src.startsWith("/") && baseUrl) {
|
|
8094
|
+
src = `${baseUrl.replace(/\/$/, "")}${src}`;
|
|
8095
|
+
}
|
|
8096
|
+
if (!seenUrls.has(src)) {
|
|
8097
|
+
seenUrls.add(src);
|
|
8098
|
+
const altMatch = altRegex.exec(fullImgTag);
|
|
8099
|
+
const originalAlt = altMatch ? altMatch[1] : "";
|
|
8100
|
+
assets.push({
|
|
8101
|
+
url: src,
|
|
8102
|
+
originalAlt,
|
|
8103
|
+
matchedKeywords: this.extractKeywordsFromUrl(src, originalAlt)
|
|
8104
|
+
});
|
|
8105
|
+
}
|
|
8106
|
+
}
|
|
8107
|
+
return assets;
|
|
8108
|
+
}
|
|
8109
|
+
static selectBestImageForVariant(params) {
|
|
8110
|
+
if (!params.mediaPool || params.mediaPool.length === 0) {
|
|
8111
|
+
return params.fallbackPlaceholderUrl || "https://images.unsplash.com/photo-1581091226825-a6a2a5aee158?w=1200&q=80";
|
|
8112
|
+
}
|
|
8113
|
+
const serviceLower = params.serviceName.toLowerCase();
|
|
8114
|
+
const matchingPhotos = params.mediaPool.filter((asset) => asset.matchedKeywords?.some((kw) => serviceLower.includes(kw)));
|
|
8115
|
+
const candidatePool = matchingPhotos.length > 0 ? matchingPhotos : params.mediaPool;
|
|
8116
|
+
const selectedIndex = params.variantIndex % candidatePool.length;
|
|
8117
|
+
return candidatePool[selectedIndex].url;
|
|
8118
|
+
}
|
|
8119
|
+
static extractKeywordsFromUrl(url, alt) {
|
|
8120
|
+
const filename = url.split("/").pop()?.split("?")[0] || "";
|
|
8121
|
+
const cleanText = `${filename} ${alt}`.toLowerCase().replace(/[-_.]/g, " ");
|
|
8122
|
+
return cleanText.split(/\s+/).filter((w) => w.length > 3);
|
|
8123
|
+
}
|
|
8124
|
+
}
|
|
8079
8125
|
// packages/lynx-seo-engine/src/features-knowledge-harvester.ts
|
|
8080
8126
|
class FeaturesKnowledgeHarvester2 {
|
|
8081
8127
|
static knowledgeStore = new Map;
|
|
@@ -8680,6 +8726,7 @@ export {
|
|
|
8680
8726
|
FreePublicToolsEngine,
|
|
8681
8727
|
FeaturesKnowledgeHarvester2 as FeaturesKnowledgeHarvester,
|
|
8682
8728
|
ExtendedSchemaGraphBuilder,
|
|
8729
|
+
ExistingMediaHarvester,
|
|
8683
8730
|
EmbeddableSeoWidgetGenerator,
|
|
8684
8731
|
DeepCrawlerAuditor,
|
|
8685
8732
|
CrosslinkScorerEngine,
|
package/package.json
CHANGED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 📸 Existing Media Harvester & Asset Pool Engine
|
|
3
|
+
*
|
|
4
|
+
* Reuses real, pre-existing photos from the client's website & WordPress Media Library:
|
|
5
|
+
* 1. 0 € GPU Cost & 0s Compute (Zero VRAM Saturation Guarantee)
|
|
6
|
+
* 2. Maximum Google E-E-A-T Authenticity (Real brand photos > Generic AI images)
|
|
7
|
+
* 3. Rotates existing photos across the 6 page variations
|
|
8
|
+
* 4. Dynamically injects localized <img alt="..."> tags across 40+ languages in RAM (< 0.01ms)
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface HarvestedMediaAsset {
|
|
12
|
+
id?: string | number;
|
|
13
|
+
url: string;
|
|
14
|
+
originalAlt?: string;
|
|
15
|
+
matchedKeywords?: string[];
|
|
16
|
+
width?: number;
|
|
17
|
+
height?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class ExistingMediaHarvester {
|
|
21
|
+
/**
|
|
22
|
+
* Extracts all existing image URLs from HTML pages or WordPress Media API
|
|
23
|
+
*/
|
|
24
|
+
static harvestFromHtml(htmlContent: string, baseUrl = ""): HarvestedMediaAsset[] {
|
|
25
|
+
const assets: HarvestedMediaAsset[] = [];
|
|
26
|
+
const imgRegex = /<img\s+[^>]*src=["']([^"']+)["'][^>]*>/gi;
|
|
27
|
+
const altRegex = /alt=["']([^"']*)["']/i;
|
|
28
|
+
|
|
29
|
+
let match: RegExpExecArray | null;
|
|
30
|
+
const seenUrls = new Set<string>();
|
|
31
|
+
|
|
32
|
+
while ((match = imgRegex.exec(htmlContent)) !== null) {
|
|
33
|
+
const fullImgTag = match[0];
|
|
34
|
+
let src = match[1];
|
|
35
|
+
|
|
36
|
+
// Exclude tiny tracking pixels, icons or avatars
|
|
37
|
+
if (
|
|
38
|
+
src.includes("gravatar.com") ||
|
|
39
|
+
src.includes("icon-") ||
|
|
40
|
+
src.includes(".svg") ||
|
|
41
|
+
src.includes("1x1")
|
|
42
|
+
) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (src.startsWith("/") && baseUrl) {
|
|
47
|
+
src = `${baseUrl.replace(/\/$/, "")}${src}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!seenUrls.has(src)) {
|
|
51
|
+
seenUrls.add(src);
|
|
52
|
+
const altMatch = altRegex.exec(fullImgTag);
|
|
53
|
+
const originalAlt = altMatch ? altMatch[1] : "";
|
|
54
|
+
|
|
55
|
+
assets.push({
|
|
56
|
+
url: src,
|
|
57
|
+
originalAlt,
|
|
58
|
+
matchedKeywords: this.extractKeywordsFromUrl(src, originalAlt),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return assets;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Matches the best existing photo from the pool for a given service & variation
|
|
68
|
+
*/
|
|
69
|
+
static selectBestImageForVariant(params: {
|
|
70
|
+
serviceName: string;
|
|
71
|
+
variantIndex: number;
|
|
72
|
+
mediaPool: HarvestedMediaAsset[];
|
|
73
|
+
fallbackPlaceholderUrl?: string;
|
|
74
|
+
}): string {
|
|
75
|
+
if (!params.mediaPool || params.mediaPool.length === 0) {
|
|
76
|
+
return params.fallbackPlaceholderUrl || "https://images.unsplash.com/photo-1581091226825-a6a2a5aee158?w=1200&q=80";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const serviceLower = params.serviceName.toLowerCase();
|
|
80
|
+
|
|
81
|
+
// 1. Try to find a photo whose filename or original alt matches the service
|
|
82
|
+
const matchingPhotos = params.mediaPool.filter((asset) =>
|
|
83
|
+
asset.matchedKeywords?.some((kw) => serviceLower.includes(kw))
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const candidatePool = matchingPhotos.length > 0 ? matchingPhotos : params.mediaPool;
|
|
87
|
+
|
|
88
|
+
// 2. Rotate deterministically across variations so each variant gets a different photo
|
|
89
|
+
const selectedIndex = params.variantIndex % candidatePool.length;
|
|
90
|
+
return candidatePool[selectedIndex].url;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private static extractKeywordsFromUrl(url: string, alt: string): string[] {
|
|
94
|
+
const filename = url.split("/").pop()?.split("?")[0] || "";
|
|
95
|
+
const cleanText = `${filename} ${alt}`.toLowerCase().replace(/[-_.]/g, " ");
|
|
96
|
+
return cleanText.split(/\s+/).filter((w) => w.length > 3);
|
|
97
|
+
}
|
|
98
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -66,6 +66,7 @@ export * from "./real-reviews-sync";
|
|
|
66
66
|
export * from "./google-business-profile";
|
|
67
67
|
export * from "./video-youtube-analyzer";
|
|
68
68
|
export * from "./power-words-psychology";
|
|
69
|
+
export * from "./existing-media-harvester";
|
|
69
70
|
|
|
70
71
|
import { LynxSeoEngine, type EngineConfig } from "./engine";
|
|
71
72
|
import { ApiKeyGuardian } from "./auth-key";
|