seo 0.2.2 → 0.2.3

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __seoCreateRequire } from 'node:module'; const require = __seoCreateRequire(import.meta.url);
2
- import { n as load, t as version } from "./package-uOaBUbds.js";
2
+ import { n as load, t as version } from "./package-Jl7x3QBx.js";
3
3
  import { Headers, fetch as fetch$1 } from "undici";
4
4
  import { chmodSync, createWriteStream, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
5
5
  import { homedir } from "node:os";
@@ -6694,6 +6694,33 @@ function sameDocument(left, right) {
6694
6694
  function bodyWordCount(value) {
6695
6695
  return value.replace(/^---[\s\S]*?---\s*/u, "").replace(/```[\s\S]*?```/gu, " ").replace(/[#>*_`[\]()|:-]/gu, " ").split(/\s+/u).filter(Boolean).length;
6696
6696
  }
6697
+ function repeatedProseLines(markdown) {
6698
+ const counts = /* @__PURE__ */ new Map();
6699
+ let inFrontmatter = false;
6700
+ let fence;
6701
+ for (const [index, rawLine] of markdown.split(/\r?\n/u).entries()) {
6702
+ const line = rawLine.trim();
6703
+ if (index === 0 && line === "---") {
6704
+ inFrontmatter = true;
6705
+ continue;
6706
+ }
6707
+ if (inFrontmatter) {
6708
+ if (line === "---") inFrontmatter = false;
6709
+ continue;
6710
+ }
6711
+ if (!fence && (line.startsWith("```") || line.startsWith("~~~"))) {
6712
+ fence = line.startsWith("```") ? "```" : "~~~";
6713
+ continue;
6714
+ }
6715
+ if (fence) {
6716
+ if (line.startsWith(fence)) fence = void 0;
6717
+ continue;
6718
+ }
6719
+ if (line.length < 40 || /^(?:#{1,6}\s|[-+*]\s|\d+[.)]\s|>|\||`|\]\()/u.test(line)) continue;
6720
+ counts.set(line, (counts.get(line) ?? 0) + 1);
6721
+ }
6722
+ return [...counts.values()].reduce((duplicates, count) => duplicates + Math.max(0, count - 1), 0);
6723
+ }
6697
6724
  function responseIsNoindex(response, body) {
6698
6725
  if ((response.headers.get("x-robots-tag") ?? "").toLowerCase().includes("noindex")) return true;
6699
6726
  return [...body.matchAll(/<meta\s+[^>]*>/giu)].some((match) => {
@@ -6707,7 +6734,6 @@ function markdownQuality(markdown, page) {
6707
6734
  const introProbe = (page.contentSample?.replace(/\s+/gu, " ").trim())?.split(" ").slice(0, 10).join(" ");
6708
6735
  const normalizedMarkdown = markdown.replace(/\s+/gu, " ");
6709
6736
  const codeFences = markdown.match(/^```/gmu)?.length ?? 0;
6710
- const repeatedLines = [...markdown.matchAll(/^(.{12,})$/gmu)].map((match) => match[1]?.trim()).filter((line) => Boolean(line)).filter((line, index, lines) => lines.indexOf(line) !== index).length;
6711
6737
  const wordCount = bodyWordCount(markdown);
6712
6738
  const sourceWordCount = page.wordCount ?? 0;
6713
6739
  return {
@@ -6722,7 +6748,7 @@ function markdownQuality(markdown, page) {
6722
6748
  rawScriptTags: markdown.match(/<script\b/giu)?.length ?? 0,
6723
6749
  rawStyleTags: markdown.match(/<style\b/giu)?.length ?? 0,
6724
6750
  suspiciousConcatenations: markdown.match(/\b[a-z]{4,}[A-Z][A-Za-z]{3,}\b/gu)?.length ?? 0,
6725
- repeatedLines,
6751
+ repeatedLines: repeatedProseLines(markdown),
6726
6752
  sourceWordCount,
6727
6753
  wordRetentionRatio: sourceWordCount > 0 ? Math.round(wordCount / sourceWordCount * 1e3) / 1e3 : null,
6728
6754
  introductoryCopyRetained: introProbe ? normalizedMarkdown.includes(introProbe) : null,
@@ -7270,7 +7296,7 @@ function qualityFailureUrls(discovery) {
7270
7296
  return discovery.markdownAlternates.pages.filter((page) => {
7271
7297
  const quality = page.quality;
7272
7298
  if (!quality) return true;
7273
- return !quality.frontmatterTitle || quality.h1Count !== 1 || !quality.codeFenceBalanced || quality.rawHtmlTags > 0 || quality.rawSvgTags > 0 || quality.rawScriptTags > 0 || quality.rawStyleTags > 0 || quality.navigationOnly || quality.repeatedLines > 0 || quality.wordRetentionRatio !== null && quality.wordRetentionRatio < .4 || quality.introductoryCopyRetained === false;
7299
+ return !quality.frontmatterTitle || quality.h1Count !== 1 || !quality.codeFenceBalanced || quality.rawHtmlTags > 0 || quality.rawSvgTags > 0 || quality.rawScriptTags > 0 || quality.rawStyleTags > 0 || quality.navigationOnly || quality.repeatedLines > 0 || quality.wordRetentionRatio !== null && quality.wordRetentionRatio < .4;
7274
7300
  }).map((page) => page.htmlUrl);
7275
7301
  }
7276
7302
  function profileChecks(discovery) {