Skip to content

Commit

Permalink
duplicate search init
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil-aexol committed Nov 17, 2023
1 parent 930441a commit 85ee150
Show file tree
Hide file tree
Showing 32 changed files with 542 additions and 272 deletions.
29 changes: 17 additions & 12 deletions packages/landing-friend-core/src/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ import open, { apps } from "open";
import path from "path";

import {
AdditionalTagsName,
AdvancedTagsName,
AllTagsName,
checkFiles,
CombinedPatterns,
CombineTagsWithReason,
ConfigFile,
fileLocation,
FileName,
fileName,
getHtmlFiles,
matchedSetting,
message,
pathName,
prepareHTMLWithTables,
saveAnalyze,
saveFile,
} from "@/index.js";

export const websiteAnalyzer = async (config: ConfigFile, interval: NodeJS.Timer) => {
export const websiteAnalyzer = async (config: ConfigFile, interval?: NodeJS.Timer) => {
const { input, analyzer, advancedAnalyzer, excludedPage, sitemap, domain } = config;
if (!analyzer) {
return message("Define analyzer in config", "redBright");
Expand All @@ -38,8 +43,8 @@ export const websiteAnalyzer = async (config: ConfigFile, interval: NodeJS.Timer
) {
combinedTagsPatternsArray.push(
await checkFiles({
file,
input,
file: file.replace("\\", "/"),
input: input.replace(/\.\//g, ""),
tags: analyzer,
advancedTags: advancedAnalyzer,
domain,
Expand Down Expand Up @@ -73,7 +78,8 @@ export const websiteAnalyzer = async (config: ConfigFile, interval: NodeJS.Timer
quantity: value.quantity,
content: value.content,
forbiddenCharacters: value.forbiddenCharacters,
keywordsIncluded: tag !== "keywords" ? value.keywordsIncluded : undefined,
keywordsIncluded:
tag !== AdditionalTagsName.Keywords ? value.keywordsIncluded : undefined,
multipleTags: value.multipleTags,
tagAmount: tag in AdvancedTagsName ? value.tagAmount : undefined,
listOfFoundMeta: value.listOfFoundMeta,
Expand All @@ -87,23 +93,22 @@ export const websiteAnalyzer = async (config: ConfigFile, interval: NodeJS.Timer
});
});

const location = "./SEO";
const fileName = (extension: ".json" | ".html") => `seo-analyze${extension}`;
const pathname = (extension: ".json" | ".html") => `${location}/${fileName(extension)}`;
clearTimeout(interval);
try {
saveAnalyze(pathname(".json"), JSON.stringify(cleanedTagsPatterns, null, 2));
saveAnalyze(pathname(".html"), htmlWithTablesAndCharts);
saveFile(pathName(FileName.analyze, ".json"), JSON.stringify(cleanedTagsPatterns, null, 2));
saveFile(pathName(FileName.analyze, ".html"), htmlWithTablesAndCharts);
message(
"Your website has been analyzed, JSON and html files have been generated in ./SEO",
"green"
);
} catch {
message("Failed to create files", "red");
} finally {
if (fs.existsSync(path.join(process.cwd(), location, fileName(".html")))) {
if (
fs.existsSync(path.join(process.cwd(), fileLocation, fileName(FileName.analyze, ".html")))
) {
try {
await open(path.join(process.cwd(), location, fileName(".html")), {
await open(path.join(process.cwd(), fileLocation, fileName(FileName.analyze, ".html")), {
app: { name: apps.browser },
});
message("The analysis file has been opened in your browser.", "green");
Expand Down
4 changes: 4 additions & 0 deletions packages/landing-friend-core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export const EXTENDED_ADVANCED_ANALYZER_GLOBAL_CONFIG_FILE: Pick<ConfigFile, "ad
},
};

export const EXTENDED_DUPLICATED_ANALYZER_CONFIG_FILE: Pick<ConfigFile, "searchDuplicated"> = {
searchDuplicated: true,
};

export const readConfig = (filePath: string, option: "init" | "generate") => {
if (!fs.existsSync(filePath)) {
if (option === "generate") {
Expand Down
1 change: 1 addition & 0 deletions packages/landing-friend-core/src/data/filePath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const fileLocation = "./SEO";
20 changes: 20 additions & 0 deletions packages/landing-friend-core/src/data/forbiddenChar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const forbiddenCharacters = [
"!",
"|",
":",
"ı",
"&",
"<",
">",
""",
"/",
"`",
"‘",
"’",
"‹",
"›",
" ",
"­",
"´",
"¸",
];
5 changes: 4 additions & 1 deletion packages/landing-friend-core/src/data/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export * from "./exclude.js";
export * from "./filePath.js";
export * from "./forbiddenChar.js";
export * from "./staticTags.js";
export * from "./unicode.js";
73 changes: 73 additions & 0 deletions packages/landing-friend-core/src/data/staticTags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
export const staticTags = [
"a",
"abbr",
"acronym",
"address",
"audio",
"b",
"bdi",
"bdo",
"blockquote",
"br",
"canvas",
"caption",
"cite",
"code",
"col",
"colgroup",
"dd",
"del",
"dfn",
"div",
"dl",
"dt",
"em",
"embed",
"figure",
"figcaption",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"iframe",
"ins",
"kbd",
"li",
"mark",
"noscript",
"object",
"ol",
"p",
"param",
"path",
"picture",
"pre",
"q",
"rp",
"rt",
"ruby",
"samp",
"script",
"small",
"span",
"strong",
"style",
"sub",
"sup",
"svg",
"table",
"tbody",
"td",
"tfoot",
"th",
"thead",
"time",
"track",
"tr",
"ul",
"var",
"video",
"wbr",
];
Original file line number Diff line number Diff line change
Expand Up @@ -104,98 +104,3 @@ export const unicode = {
"&thorn;": "þ",
"&yuml;": "ÿ",
};

export const staticTags = [
"a",
"abbr",
"acronym",
"address",
"audio",
"b",
"bdi",
"bdo",
"blockquote",
"br",
"canvas",
"caption",
"cite",
"code",
"col",
"colgroup",
"dd",
"del",
"dfn",
"div",
"dl",
"dt",
"em",
"embed",
"figure",
"figcaption",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"iframe",
"ins",
"kbd",
"li",
"mark",
"noscript",
"object",
"ol",
"p",
"param",
"path",
"picture",
"pre",
"q",
"rp",
"rt",
"ruby",
"samp",
"script",
"small",
"span",
"strong",
"style",
"sub",
"sup",
"svg",
"table",
"tbody",
"td",
"tfoot",
"th",
"thead",
"time",
"track",
"tr",
"ul",
"var",
"video",
"wbr",
];

export const forbiddenCharacters = [
"!",
"|",
":",
"ı",
"&",
"<",
">",
""",
"/",
"`",
"‘",
"’",
"‹",
"›",
" ",
"­",
"´",
"¸",
];
1 change: 1 addition & 0 deletions packages/landing-friend-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "./analyzer.js";
export * from "./config.js";
export * from "./console.js";
export * from "./data/index.js";
export * from "./searchDuplicated.js";
export * from "./sitemap.js";
export * from "./types/index.js";
export * from "./utils/index.js";
74 changes: 74 additions & 0 deletions packages/landing-friend-core/src/searchDuplicated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import fs from "fs";
import open, { apps } from "open";
import path from "path";

import {
ConfigFile,
fileLocation,
FileName,
fileName,
FileWithDuplicateContent,
getContent,
getHtmlFiles,
matchedSetting,
message,
pathName,
saveFile,
} from "@/index.js";

export const searchDuplicated = async (config: ConfigFile, interval?: NodeJS.Timer) => {
const { input, searchDuplicated, excludedPage } = config;

if (!searchDuplicated) {
return message("Define analyzer in config", "redBright");
}

const contentArray: FileWithDuplicateContent[] = [];

const allHtmlFiles = getHtmlFiles(input, false);

for (const file of allHtmlFiles) {
if (
!matchedSetting(
file
.replace("\\", "/")
.replace(/\.html|\.php/g, "")
.replace(/index/g, "")
.replace(/\/$/g, ""),
excludedPage
)
) {
contentArray.push(
await getContent({
file: file.replace("\\", "/"),
input: input.replace(/\.\//g, ""),
})
);
}
}

clearTimeout(interval);
try {
saveFile(pathName(FileName.duplicated, ".json"), JSON.stringify(contentArray, null, 2));
// saveFile(pathName(FileName.duplicated, ".html"), htmlWithTablesAndCharts);
message(
"Your website has been analyzed, JSON and html files have been generated in ./SEO",
"green"
);
} catch {
message("Failed to create files", "red");
} finally {
if (
fs.existsSync(path.join(process.cwd(), fileLocation, fileName(FileName.duplicated, ".html")))
) {
try {
await open(path.join(process.cwd(), fileLocation, fileName(FileName.duplicated, ".html")), {
app: { name: apps.browser },
});
message("The analysis file has been opened in your browser.", "green");
} catch {
message("Cannot open browser. Please open file manually", "red");
}
}
}
};
Loading

0 comments on commit 85ee150

Please sign in to comment.