next-seo-checker 1.0.0
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/README.md +129 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Next SEO Checker 🚀
|
|
2
|
+
|
|
3
|
+
A comprehensive, live SEO optimizer and permalink management suite for Next.js App Router applications. Ensure peak SEO performance with real-time analysis and persistent metadata management.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ **Live SEO Analysis:** Real-time feedback on title length, meta description, keyword density, and content structure.
|
|
8
|
+
- ✅ **Server-Side Persistence:** SEO overrides are saved to a local `seo-overrides.json` file and served via SSR for perfect search engine indexing.
|
|
9
|
+
- ✅ **Permalink Manager:** Override URL slugs without changing your file-based routing structure.
|
|
10
|
+
- ✅ **Advanced Data-Driven Scoring:** Dynamic SEO score calculation based on primary and secondary focus keywords.
|
|
11
|
+
- ✅ **Zero-Configuration UI:** A sleek, non-intrusive floating panel for development mode.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install next-seo-checker
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### 1. Set up the Persistence API
|
|
22
|
+
Create an API route to handle saving and loading your SEO data.
|
|
23
|
+
|
|
24
|
+
`app/api/seo/save/route.ts`:
|
|
25
|
+
```typescript
|
|
26
|
+
import { NextResponse } from "next/server";
|
|
27
|
+
import fs from "fs";
|
|
28
|
+
import path from "path";
|
|
29
|
+
|
|
30
|
+
export async function GET() {
|
|
31
|
+
const filePath = path.join(process.cwd(), "seo-overrides.json");
|
|
32
|
+
if (!fs.existsSync(filePath)) return NextResponse.json({});
|
|
33
|
+
const data = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
34
|
+
return NextResponse.json(data);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function POST(req: Request) {
|
|
38
|
+
const { pathname, overrides } = await req.json();
|
|
39
|
+
const filePath = path.join(process.cwd(), "seo-overrides.json");
|
|
40
|
+
|
|
41
|
+
let allData = {};
|
|
42
|
+
if (fs.existsSync(filePath)) {
|
|
43
|
+
allData = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
allData[pathname] = overrides;
|
|
47
|
+
fs.writeFileSync(filePath, JSON.stringify(allData, null, 2));
|
|
48
|
+
return NextResponse.json({ success: true });
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 2. Configure Middleware (Optional, for Permalinks)
|
|
53
|
+
If you want to use the Permalink Manager, add this to your `middleware.ts`:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { NextResponse } from "next/server";
|
|
57
|
+
import type { NextRequest } from "next/server";
|
|
58
|
+
|
|
59
|
+
export async function middleware(request: NextRequest) {
|
|
60
|
+
const { pathname, origin } = request.nextUrl;
|
|
61
|
+
|
|
62
|
+
// Skip static files and API routes
|
|
63
|
+
if (pathname.includes('.') || pathname.startsWith('/api') || pathname.startsWith('/_next')) {
|
|
64
|
+
return NextResponse.next();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const res = await fetch(`${origin}/api/seo/save`);
|
|
69
|
+
const allData = await res.json();
|
|
70
|
+
const headers = new Headers(request.headers);
|
|
71
|
+
|
|
72
|
+
// Slug Redirect Logic (Real path -> SEO Slug)
|
|
73
|
+
const currentOverride = allData[pathname];
|
|
74
|
+
if (currentOverride?.slug && pathname !== `/${currentOverride.slug}`) {
|
|
75
|
+
return NextResponse.redirect(new URL(`/${currentOverride.slug}`, request.url));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Slug Rewrite Logic (SEO Slug -> Real path)
|
|
79
|
+
for (const [realPath, data] of Object.entries(allData)) {
|
|
80
|
+
if ((data as any).slug && pathname === `/${(data as any).slug}`) {
|
|
81
|
+
headers.set("x-url", realPath);
|
|
82
|
+
return NextResponse.rewrite(new URL(realPath, request.url), { request: { headers } });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} catch (e) {}
|
|
86
|
+
|
|
87
|
+
return NextResponse.next();
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 3. Integrate with Root Layout
|
|
92
|
+
`app/layout.tsx`:
|
|
93
|
+
```tsx
|
|
94
|
+
import { NextSeoChecker, getSeoMetadata } from "next-seo-checker";
|
|
95
|
+
import { headers } from "next/headers";
|
|
96
|
+
|
|
97
|
+
export async function generateMetadata() {
|
|
98
|
+
const head = await headers();
|
|
99
|
+
const pathname = head.get("x-url") || "/";
|
|
100
|
+
|
|
101
|
+
const defaultSeo = {
|
|
102
|
+
title: "My Awesome Site",
|
|
103
|
+
description: "Welcome to my website"
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return getSeoMetadata(pathname, defaultSeo);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export default function RootLayout({ children }) {
|
|
110
|
+
return (
|
|
111
|
+
<html>
|
|
112
|
+
<body>
|
|
113
|
+
{children}
|
|
114
|
+
<NextSeoChecker />
|
|
115
|
+
</body>
|
|
116
|
+
</html>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## How it Works
|
|
122
|
+
|
|
123
|
+
1. **Analyze:** Use the floating badge in `development` mode to check your page's SEO performance.
|
|
124
|
+
2. **Edit:** Set focus keywords, titles, descriptions, and custom permalinks directly in the UI.
|
|
125
|
+
3. **Save:** Click "Save to Project" to write changes to `seo-overrides.json`.
|
|
126
|
+
4. **Index:** Search engines receive the updated metadata on the very first request (SSR), while your custom permalinks handled by the middleware ensure the best URL structure.
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { Metadata } from 'next';
|
|
3
|
+
|
|
4
|
+
declare function NextSeoChecker(): react_jsx_runtime.JSX.Element | null;
|
|
5
|
+
|
|
6
|
+
declare function getSeoMetadata(pathname: string, defaultMetadata: Metadata): Metadata;
|
|
7
|
+
|
|
8
|
+
export { NextSeoChecker, getSeoMetadata };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { Metadata } from 'next';
|
|
3
|
+
|
|
4
|
+
declare function NextSeoChecker(): react_jsx_runtime.JSX.Element | null;
|
|
5
|
+
|
|
6
|
+
declare function getSeoMetadata(pathname: string, defaultMetadata: Metadata): Metadata;
|
|
7
|
+
|
|
8
|
+
export { NextSeoChecker, getSeoMetadata };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var ne=Object.create;var O=Object.defineProperty,se=Object.defineProperties,re=Object.getOwnPropertyDescriptor,ae=Object.getOwnPropertyDescriptors,de=Object.getOwnPropertyNames,Y=Object.getOwnPropertySymbols,le=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var _=(i,o,s)=>o in i?O(i,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[o]=s,R=(i,o)=>{for(var s in o||(o={}))Q.call(o,s)&&_(i,s,o[s]);if(Y)for(var s of Y(o))ce.call(o,s)&&_(i,s,o[s]);return i},E=(i,o)=>se(i,ae(o));var pe=(i,o)=>{for(var s in o)O(i,s,{get:o[s],enumerable:!0})},X=(i,o,s,S)=>{if(o&&typeof o=="object"||typeof o=="function")for(let l of de(o))!Q.call(i,l)&&l!==s&&O(i,l,{get:()=>o[l],enumerable:!(S=re(o,l))||S.enumerable});return i};var Z=(i,o,s)=>(s=i!=null?ne(le(i)):{},X(o||!i||!i.__esModule?O(s,"default",{value:i,enumerable:!0}):s,i)),ue=i=>X(O({},"__esModule",{value:!0}),i);var ye={};pe(ye,{NextSeoChecker:()=>fe,getSeoMetadata:()=>ge});module.exports=ue(ye);var a=require("react"),ee=require("next/navigation");var e=require("react/jsx-runtime");function fe(){var J;let i=(0,ee.usePathname)(),[o,s]=(0,a.useState)(!1),[S,l]=(0,a.useState)(!1),[D,P]=(0,a.useState)("general"),[g,K]=(0,a.useState)({}),[C,N]=(0,a.useState)(""),[T,j]=(0,a.useState)(""),[F,M]=(0,a.useState)(""),[A,H]=(0,a.useState)(""),[h,oe]=(0,a.useState)({h1s:[],h2s:[],h3s:[],bodyText:"",images:[],url:"",wordCount:0}),I=process.env.NODE_ENV==="development",U=(0,a.useRef)(0),$=(0,a.useCallback)(async()=>{var t;try{let d=await(await fetch("/api/seo/save")).json(),n=d[i];if(!n){let c=i.replace(/^\//,""),m=Object.keys(d).find(v=>d[v].slug===c);m&&(n=d[m])}n&&(K(n),N(n.title||(typeof document!="undefined"?document.title:"")),j(n.description||(typeof document!="undefined"?(t=document.querySelector('meta[name="description"]'))==null?void 0:t.getAttribute("content"):"")||""),M(n.slug||i.split("/").pop()||""))}catch(r){console.error("Failed to load SEO data from server")}},[i]);(0,a.useEffect)(()=>{s(!0),I&&$()},[I,$]);let ie=async()=>{let t=E(R({},g),{title:C,description:T,slug:F});try{if((await fetch("/api/seo/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pathname:i,overrides:t})})).ok&&(K(t),alert("SEO Changes & Permalink Mapping Saved! \u{1F680}"),typeof document!="undefined")){document.title=C;let d=document.querySelector('meta[name="description"]');d&&d.setAttribute("content",T)}}catch(r){alert("Failed to save to project.")}},q=async t=>{let r=E(R({},g),{keywords:t});try{await fetch("/api/seo/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pathname:i,overrides:r})}),K(r)}catch(d){}};(0,a.useEffect)(()=>{if(!o)return;let t=()=>{if(typeof document=="undefined")return;let n=Date.now();if(n-U.current<2e3)return;U.current=n;let c=Array.from(document.getElementsByTagName("h1")).map(p=>p.innerText),m=Array.from(document.getElementsByTagName("h2")).map(p=>p.innerText),v=Array.from(document.getElementsByTagName("h3")).map(p=>p.innerText),y=document.getElementById("next-seo-checker-root"),f=document.body.innerText;y&&(f=f.replace(y.innerText,""));let z=Array.from(document.getElementsByTagName("img")).filter(p=>!(y!=null&&y.contains(p))).map(p=>({alt:p.alt})),B=f.trim()===""?0:f.trim().split(/\s+/).length;oe({h1s:c,h2s:m,h3s:v,bodyText:f,images:z,url:window.location.pathname,wordCount:B})},r=setTimeout(t,1e3),d=new MutationObserver(n=>{let c=document.getElementById("next-seo-checker-root");n.some(v=>!(c!=null&&c.contains(v.target)))&&t()});return d.observe(document.body,{childList:!0,subtree:!0,attributes:!0}),()=>{clearTimeout(r),d.disconnect()}},[i,o]);let W=(0,a.useMemo)(()=>{var B,p;if(!o)return[];let t=(g.title||(typeof document!="undefined"?document.title:"")).toLowerCase(),r=(g.description||(typeof document!="undefined"?(B=document.querySelector('meta[name="description"]'))==null?void 0:B.getAttribute("content"):"")||"").toLowerCase(),d=g.keywords||[],n=((p=d[0])==null?void 0:p.toLowerCase())||"",c=d.slice(1).map(u=>u.toLowerCase()),m=h.bodyText.toLowerCase(),v=g.slug||(i==="/"?"home":i.split("/").filter(Boolean).pop())||"",y=[{title:"Basic SEO",items:[]},{title:"Additional",items:[]},{title:"Title Readability",items:[]},{title:"Content Readability",items:[]}],f=y[0].items;if(n){let u=t.includes(n);f.push({id:"key-title",label:"Primary Keyword in Title",status:u?"success":"error",message:u?"Perfect! Keyword found in title.":"Critical: Primary keyword missing in title!"});let w=r.includes(n);f.push({id:"key-desc",label:"Primary Keyword in Description",status:w?"success":"error",message:w?"Keyword found in description.":"Critical: Primary keyword missing in description!"});let b=n.replace(/\s+/g,"-"),G=v.toLowerCase().includes(b);f.push({id:"key-url",label:"Keyword in Permalink",status:G?"success":"error",message:G?"Focus keyword used in URL slug.":"Error: Focus keyword not found in your URL slug!"});let V=m.substring(0,500).includes(n);f.push({id:"key-start",label:"Keyword in beginning",status:V?"success":"warning",message:V?"Keyword found at content start.":"Try using keyword in the first 10% of content."})}f.push({id:"word-count",label:"Word Count",status:h.wordCount>600?"success":"warning",message:`${h.wordCount} words. (Rank Math goal: 600+)`});let z=y[1].items;if(c.length>0&&c.forEach((u,w)=>{let b=m.includes(u)||t.includes(u)||r.includes(u);z.push({id:`sec-key-${w}`,label:`Secondary Keyword: ${u}`,status:b?"success":"error",message:b?"Keyword used in content.":"Error: This keyword is not found anywhere!"})}),n){let u=[...h.h2s,...h.h3s].some(b=>b.toLowerCase().includes(n));z.push({id:"key-sub",label:"Primary in Subheadings",status:u?"success":"warning",message:u?"Keyword found in H2/H3.":"Focus keyword not found in subheadings."});let w=h.images.some(b=>b.alt.toLowerCase().includes(n));z.push({id:"key-alt",label:"Image Alt Tags",status:w?"success":"warning",message:w?"Keyword found in image alt text.":"Add your focus keyword to image alt tags."})}return y},[h,g,o]),k=(0,a.useMemo)(()=>{let t=0,r=0;return W.forEach(d=>d.items.forEach(n=>{r++,n.status==="success"?t++:n.status==="warning"&&(t+=.5)})),r===0?0:Math.round(t/r*100)},[W]);if(!I||!o)return null;let x={wrapper:{fontFamily:"-apple-system, system-ui, sans-serif",color:"#111827"},trigger:{position:"fixed",bottom:"20px",right:"20px",zIndex:99999,background:k>=80?"#10b981":k>=50?"#f59e0b":"#ef4444",color:"white",padding:"10px 20px",borderRadius:"30px",cursor:"pointer",fontWeight:800,border:"2px solid white",boxShadow:"0 4px 15px rgba(0,0,0,0.1)"},panel:{position:"fixed",bottom:0,left:0,right:0,height:S?"600px":"0px",background:"#fff",zIndex:99998,boxShadow:"0 -4px 30px rgba(0,0,0,0.1)",transition:"height 0.3s cubic-bezier(0.4, 0, 0.2, 1)",display:"flex",flexDirection:"column"},sidebar:{width:"240px",borderRight:"1px solid #e5e7eb",padding:"24px",display:"flex",flexDirection:"column",gap:"8px",background:"#f9fafb"},main:{flex:1,padding:"32px 40px",overflowY:"auto",background:"#fff"},tab:t=>({padding:"12px 16px",borderRadius:"8px",cursor:"pointer",fontSize:"14px",fontWeight:600,background:t?"#fff":"transparent",color:t?"#2563eb":"#64748b",boxShadow:t?"0 1px 3px rgba(0,0,0,0.1)":"none",transition:"all 0.2s"}),keywordTag:t=>({background:t?"#dcfce7":"#f3f4f6",color:t?"#15803d":"#374151",padding:"6px 12px",borderRadius:"20px",fontSize:"12px",fontWeight:700,marginRight:"8px",border:"1px solid #e2e8f0",display:"inline-flex",alignItems:"center",gap:"4px"})};return(0,e.jsxs)("div",{id:"next-seo-checker-root",style:x.wrapper,children:[!S&&(0,e.jsxs)("div",{style:x.trigger,onClick:()=>l(!0),children:["Rank Math ",k]}),(0,e.jsxs)("div",{style:x.panel,children:[(0,e.jsxs)("div",{style:{height:"64px",padding:"0 40px",display:"flex",justifyContent:"space-between",alignItems:"center",borderBottom:"1px solid #e5e7eb"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[(0,e.jsx)("span",{style:{fontSize:"20px"},children:"\u{1F680}"}),(0,e.jsx)("div",{style:{fontWeight:800,fontSize:"18px"},children:"Next SEO Checker"}),(0,e.jsxs)("div",{style:{background:k>=80?"#d1fae5":"#fef3c7",color:k>=80?"#059669":"#d97706",padding:"4px 12px",borderRadius:"12px",fontSize:"14px",fontWeight:800},children:[k,"/100"]})]}),(0,e.jsx)("button",{onClick:()=>l(!1),style:{background:"none",border:"none",fontSize:"28px",cursor:"pointer",color:"#9ca3af"},children:"\xD7"})]}),(0,e.jsxs)("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[(0,e.jsxs)("div",{style:x.sidebar,children:[(0,e.jsx)("div",{style:x.tab(D==="general"),onClick:()=>P("general"),children:"\u2728 General"}),(0,e.jsx)("div",{style:x.tab(D==="edit"),onClick:()=>P("edit"),children:"\u{1F4DD} Snippet Editor"})]}),(0,e.jsxs)("div",{style:x.main,children:[D==="general"&&(0,e.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:[(0,e.jsxs)("div",{style:{background:"#f9fafb",padding:"24px",borderRadius:"15px",border:"1px solid #e5e7eb"},children:[(0,e.jsx)("div",{style:{fontSize:"11px",fontWeight:800,color:"#9ca3af",textTransform:"uppercase",marginBottom:"15px",letterSpacing:"0.5px"},children:"Focus Keywords"}),(0,e.jsxs)("div",{style:{display:"flex",gap:"10px",marginBottom:"15px"},children:[(0,e.jsx)("input",{style:{flex:1,padding:"12px 16px",borderRadius:"10px",border:"1px solid #d1d5db",outline:"none",fontSize:"14px"},value:A,onChange:t=>H(t.target.value),placeholder:"Add focus keyword..."}),(0,e.jsx)("button",{onClick:()=>{A&&(q([...g.keywords||[],A]),H(""))},style:{padding:"0 24px",background:"#2563eb",color:"white",border:"none",borderRadius:"10px",fontWeight:700,cursor:"pointer"},children:"Add"})]}),(0,e.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px"},children:(J=g.keywords)==null?void 0:J.map((t,r)=>(0,e.jsxs)("span",{style:x.keywordTag(r===0),children:[r===0&&"\u2605 "," ",t,(0,e.jsx)("span",{onClick:()=>{var n;let d=(n=g.keywords)==null?void 0:n.filter(c=>c!==t);q(d||[])},style:{cursor:"pointer",opacity:.5,marginLeft:"4px"},children:"\xD7"})]},t))})]}),W.map(t=>(0,e.jsxs)("div",{children:[(0,e.jsx)("div",{style:{fontSize:"12px",fontWeight:800,color:"#9ca3af",textTransform:"uppercase",marginBottom:"12px",marginLeft:"4px"},children:t.title}),(0,e.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:"12px"},children:t.items.map(r=>(0,e.jsxs)("div",{style:{padding:"16px",borderRadius:"12px",border:"1px solid #f3f4f6",background:"#fff",display:"flex",gap:"12px",alignItems:"flex-start",borderLeft:`4px solid ${r.status==="success"?"#10b981":r.status==="warning"?"#f59e0b":"#ef4444"}`},children:[(0,e.jsx)("div",{style:{fontSize:"16px"},children:r.status==="success"?"\u2705":r.status==="warning"?"\u26A0\uFE0F":"\u274C"}),(0,e.jsxs)("div",{children:[(0,e.jsx)("div",{style:{fontSize:"14px",fontWeight:700,marginBottom:"2px"},children:r.label}),(0,e.jsx)("div",{style:{fontSize:"12px",color:"#6b7280"},children:r.message})]})]},r.id))})]},t.title))]}),D==="edit"&&(0,e.jsx)("div",{style:{maxWidth:"650px"},children:(0,e.jsxs)("div",{style:{background:"#fff",padding:"32px",borderRadius:"15px",border:"1px solid #e5e7eb",boxShadow:"0 1px 3px rgba(0,0,0,0.05)"},children:[(0,e.jsxs)("div",{style:{marginBottom:"24px"},children:[(0,e.jsx)("label",{style:{display:"block",fontSize:"13px",fontWeight:800,color:"#374151",marginBottom:"8px"},children:"SEO Title"}),(0,e.jsx)("input",{style:{width:"100%",padding:"12px 16px",borderRadius:"10px",border:"1px solid #d1d5db",fontSize:"15px",outline:"none"},value:C,onChange:t=>N(t.target.value)}),(0,e.jsxs)("div",{style:{fontSize:"11px",marginTop:"6px",color:C.length>60?"#ef4444":"#9ca3af"},children:[C.length," / 60 characters"]})]}),(0,e.jsxs)("div",{style:{marginBottom:"24px"},children:[(0,e.jsx)("label",{style:{display:"block",fontSize:"13px",fontWeight:800,color:"#374151",marginBottom:"8px"},children:"Permalink (Slug)"}),(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",background:"#f3f4f6",borderRadius:"10px",padding:"0 12px",border:"1px solid #d1d5db"},children:[(0,e.jsx)("span",{style:{fontSize:"13px",color:"#9ca3af",marginRight:"4px"},children:"/"}),(0,e.jsx)("input",{style:{flex:1,background:"transparent",border:"none",padding:"12px 4px",fontSize:"15px",outline:"none"},value:F,onChange:t=>M(t.target.value.replace(/\s+/g,"-").toLowerCase())})]})]}),(0,e.jsxs)("div",{style:{marginBottom:"32px"},children:[(0,e.jsx)("label",{style:{display:"block",fontSize:"13px",fontWeight:800,color:"#374151",marginBottom:"8px"},children:"Meta Description"}),(0,e.jsx)("textarea",{style:{width:"100%",padding:"12px 16px",borderRadius:"10px",border:"1px solid #d1d5db",fontSize:"15px",minHeight:"120px",outline:"none",resize:"vertical"},value:T,onChange:t=>j(t.target.value)}),(0,e.jsxs)("div",{style:{fontSize:"11px",marginTop:"6px",color:T.length>160?"#ef4444":"#9ca3af"},children:[T.length," / 160 characters"]})]}),(0,e.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",gap:"12px"},children:(0,e.jsx)("button",{onClick:ie,style:{padding:"12px 24px",background:"#2563eb",color:"white",border:"none",borderRadius:"10px",fontWeight:700,cursor:"pointer",fontSize:"14px"},children:"Save to Project (Server-Side)"})})]})})]})]})]})]})}var L=Z(require("fs")),te=Z(require("path"));function ge(i,o){try{let s=te.default.join(process.cwd(),"seo-overrides.json");if(!L.default.existsSync(s))return o;let l=JSON.parse(L.default.readFileSync(s,"utf-8"))[i];return l?E(R({},o),{title:l.title||o.title,description:l.description||o.description,keywords:l.keywords||o.keywords}):o}catch(s){return console.error("SEO Helper Error:",s),o}}0&&(module.exports={NextSeoChecker,getSeoMetadata});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var te=Object.defineProperty,oe=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var V=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable;var Y=(r,o,d)=>o in r?te(r,o,{enumerable:!0,configurable:!0,writable:!0,value:d}):r[o]=d,O=(r,o)=>{for(var d in o||(o={}))ne.call(o,d)&&Y(r,d,o[d]);if(V)for(var d of V(o))se.call(o,d)&&Y(r,d,o[d]);return r},R=(r,o)=>oe(r,ie(o));import{useEffect as _,useState as y,useMemo as Q,useCallback as re,useRef as ae}from"react";import{usePathname as de}from"next/navigation";import{jsx as n,jsxs as s}from"react/jsx-runtime";function ge(){var q;let r=de(),[o,d]=y(!1),[B,h]=y(!1),[E,L]=y("general"),[f,K]=y({}),[C,P]=y(""),[T,N]=y(""),[j,F]=y(""),[A,M]=y(""),[v,Z]=y({h1s:[],h2s:[],h3s:[],bodyText:"",images:[],url:"",wordCount:0}),I=process.env.NODE_ENV==="development",H=ae(0),U=re(async()=>{var e;try{let a=await(await fetch("/api/seo/save")).json(),t=a[r];if(!t){let l=r.replace(/^\//,""),m=Object.keys(a).find(w=>a[w].slug===l);m&&(t=a[m])}t&&(K(t),P(t.title||(typeof document!="undefined"?document.title:"")),N(t.description||(typeof document!="undefined"?(e=document.querySelector('meta[name="description"]'))==null?void 0:e.getAttribute("content"):"")||""),F(t.slug||r.split("/").pop()||""))}catch(i){console.error("Failed to load SEO data from server")}},[r]);_(()=>{d(!0),I&&U()},[I,U]);let ee=async()=>{let e=R(O({},f),{title:C,description:T,slug:j});try{if((await fetch("/api/seo/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pathname:r,overrides:e})})).ok&&(K(e),alert("SEO Changes & Permalink Mapping Saved! \u{1F680}"),typeof document!="undefined")){document.title=C;let a=document.querySelector('meta[name="description"]');a&&a.setAttribute("content",T)}}catch(i){alert("Failed to save to project.")}},$=async e=>{let i=R(O({},f),{keywords:e});try{await fetch("/api/seo/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pathname:r,overrides:i})}),K(i)}catch(a){}};_(()=>{if(!o)return;let e=()=>{if(typeof document=="undefined")return;let t=Date.now();if(t-H.current<2e3)return;H.current=t;let l=Array.from(document.getElementsByTagName("h1")).map(c=>c.innerText),m=Array.from(document.getElementsByTagName("h2")).map(c=>c.innerText),w=Array.from(document.getElementsByTagName("h3")).map(c=>c.innerText),g=document.getElementById("next-seo-checker-root"),u=document.body.innerText;g&&(u=u.replace(g.innerText,""));let z=Array.from(document.getElementsByTagName("img")).filter(c=>!(g!=null&&g.contains(c))).map(c=>({alt:c.alt})),D=u.trim()===""?0:u.trim().split(/\s+/).length;Z({h1s:l,h2s:m,h3s:w,bodyText:u,images:z,url:window.location.pathname,wordCount:D})},i=setTimeout(e,1e3),a=new MutationObserver(t=>{let l=document.getElementById("next-seo-checker-root");t.some(w=>!(l!=null&&l.contains(w.target)))&&e()});return a.observe(document.body,{childList:!0,subtree:!0,attributes:!0}),()=>{clearTimeout(i),a.disconnect()}},[r,o]);let W=Q(()=>{var D,c;if(!o)return[];let e=(f.title||(typeof document!="undefined"?document.title:"")).toLowerCase(),i=(f.description||(typeof document!="undefined"?(D=document.querySelector('meta[name="description"]'))==null?void 0:D.getAttribute("content"):"")||"").toLowerCase(),a=f.keywords||[],t=((c=a[0])==null?void 0:c.toLowerCase())||"",l=a.slice(1).map(p=>p.toLowerCase()),m=v.bodyText.toLowerCase(),w=f.slug||(r==="/"?"home":r.split("/").filter(Boolean).pop())||"",g=[{title:"Basic SEO",items:[]},{title:"Additional",items:[]},{title:"Title Readability",items:[]},{title:"Content Readability",items:[]}],u=g[0].items;if(t){let p=e.includes(t);u.push({id:"key-title",label:"Primary Keyword in Title",status:p?"success":"error",message:p?"Perfect! Keyword found in title.":"Critical: Primary keyword missing in title!"});let S=i.includes(t);u.push({id:"key-desc",label:"Primary Keyword in Description",status:S?"success":"error",message:S?"Keyword found in description.":"Critical: Primary keyword missing in description!"});let b=t.replace(/\s+/g,"-"),J=w.toLowerCase().includes(b);u.push({id:"key-url",label:"Keyword in Permalink",status:J?"success":"error",message:J?"Focus keyword used in URL slug.":"Error: Focus keyword not found in your URL slug!"});let G=m.substring(0,500).includes(t);u.push({id:"key-start",label:"Keyword in beginning",status:G?"success":"warning",message:G?"Keyword found at content start.":"Try using keyword in the first 10% of content."})}u.push({id:"word-count",label:"Word Count",status:v.wordCount>600?"success":"warning",message:`${v.wordCount} words. (Rank Math goal: 600+)`});let z=g[1].items;if(l.length>0&&l.forEach((p,S)=>{let b=m.includes(p)||e.includes(p)||i.includes(p);z.push({id:`sec-key-${S}`,label:`Secondary Keyword: ${p}`,status:b?"success":"error",message:b?"Keyword used in content.":"Error: This keyword is not found anywhere!"})}),t){let p=[...v.h2s,...v.h3s].some(b=>b.toLowerCase().includes(t));z.push({id:"key-sub",label:"Primary in Subheadings",status:p?"success":"warning",message:p?"Keyword found in H2/H3.":"Focus keyword not found in subheadings."});let S=v.images.some(b=>b.alt.toLowerCase().includes(t));z.push({id:"key-alt",label:"Image Alt Tags",status:S?"success":"warning",message:S?"Keyword found in image alt text.":"Add your focus keyword to image alt tags."})}return g},[v,f,o]),k=Q(()=>{let e=0,i=0;return W.forEach(a=>a.items.forEach(t=>{i++,t.status==="success"?e++:t.status==="warning"&&(e+=.5)})),i===0?0:Math.round(e/i*100)},[W]);if(!I||!o)return null;let x={wrapper:{fontFamily:"-apple-system, system-ui, sans-serif",color:"#111827"},trigger:{position:"fixed",bottom:"20px",right:"20px",zIndex:99999,background:k>=80?"#10b981":k>=50?"#f59e0b":"#ef4444",color:"white",padding:"10px 20px",borderRadius:"30px",cursor:"pointer",fontWeight:800,border:"2px solid white",boxShadow:"0 4px 15px rgba(0,0,0,0.1)"},panel:{position:"fixed",bottom:0,left:0,right:0,height:B?"600px":"0px",background:"#fff",zIndex:99998,boxShadow:"0 -4px 30px rgba(0,0,0,0.1)",transition:"height 0.3s cubic-bezier(0.4, 0, 0.2, 1)",display:"flex",flexDirection:"column"},sidebar:{width:"240px",borderRight:"1px solid #e5e7eb",padding:"24px",display:"flex",flexDirection:"column",gap:"8px",background:"#f9fafb"},main:{flex:1,padding:"32px 40px",overflowY:"auto",background:"#fff"},tab:e=>({padding:"12px 16px",borderRadius:"8px",cursor:"pointer",fontSize:"14px",fontWeight:600,background:e?"#fff":"transparent",color:e?"#2563eb":"#64748b",boxShadow:e?"0 1px 3px rgba(0,0,0,0.1)":"none",transition:"all 0.2s"}),keywordTag:e=>({background:e?"#dcfce7":"#f3f4f6",color:e?"#15803d":"#374151",padding:"6px 12px",borderRadius:"20px",fontSize:"12px",fontWeight:700,marginRight:"8px",border:"1px solid #e2e8f0",display:"inline-flex",alignItems:"center",gap:"4px"})};return s("div",{id:"next-seo-checker-root",style:x.wrapper,children:[!B&&s("div",{style:x.trigger,onClick:()=>h(!0),children:["Rank Math ",k]}),s("div",{style:x.panel,children:[s("div",{style:{height:"64px",padding:"0 40px",display:"flex",justifyContent:"space-between",alignItems:"center",borderBottom:"1px solid #e5e7eb"},children:[s("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[n("span",{style:{fontSize:"20px"},children:"\u{1F680}"}),n("div",{style:{fontWeight:800,fontSize:"18px"},children:"Next SEO Checker"}),s("div",{style:{background:k>=80?"#d1fae5":"#fef3c7",color:k>=80?"#059669":"#d97706",padding:"4px 12px",borderRadius:"12px",fontSize:"14px",fontWeight:800},children:[k,"/100"]})]}),n("button",{onClick:()=>h(!1),style:{background:"none",border:"none",fontSize:"28px",cursor:"pointer",color:"#9ca3af"},children:"\xD7"})]}),s("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[s("div",{style:x.sidebar,children:[n("div",{style:x.tab(E==="general"),onClick:()=>L("general"),children:"\u2728 General"}),n("div",{style:x.tab(E==="edit"),onClick:()=>L("edit"),children:"\u{1F4DD} Snippet Editor"})]}),s("div",{style:x.main,children:[E==="general"&&s("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:[s("div",{style:{background:"#f9fafb",padding:"24px",borderRadius:"15px",border:"1px solid #e5e7eb"},children:[n("div",{style:{fontSize:"11px",fontWeight:800,color:"#9ca3af",textTransform:"uppercase",marginBottom:"15px",letterSpacing:"0.5px"},children:"Focus Keywords"}),s("div",{style:{display:"flex",gap:"10px",marginBottom:"15px"},children:[n("input",{style:{flex:1,padding:"12px 16px",borderRadius:"10px",border:"1px solid #d1d5db",outline:"none",fontSize:"14px"},value:A,onChange:e=>M(e.target.value),placeholder:"Add focus keyword..."}),n("button",{onClick:()=>{A&&($([...f.keywords||[],A]),M(""))},style:{padding:"0 24px",background:"#2563eb",color:"white",border:"none",borderRadius:"10px",fontWeight:700,cursor:"pointer"},children:"Add"})]}),n("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px"},children:(q=f.keywords)==null?void 0:q.map((e,i)=>s("span",{style:x.keywordTag(i===0),children:[i===0&&"\u2605 "," ",e,n("span",{onClick:()=>{var t;let a=(t=f.keywords)==null?void 0:t.filter(l=>l!==e);$(a||[])},style:{cursor:"pointer",opacity:.5,marginLeft:"4px"},children:"\xD7"})]},e))})]}),W.map(e=>s("div",{children:[n("div",{style:{fontSize:"12px",fontWeight:800,color:"#9ca3af",textTransform:"uppercase",marginBottom:"12px",marginLeft:"4px"},children:e.title}),n("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:"12px"},children:e.items.map(i=>s("div",{style:{padding:"16px",borderRadius:"12px",border:"1px solid #f3f4f6",background:"#fff",display:"flex",gap:"12px",alignItems:"flex-start",borderLeft:`4px solid ${i.status==="success"?"#10b981":i.status==="warning"?"#f59e0b":"#ef4444"}`},children:[n("div",{style:{fontSize:"16px"},children:i.status==="success"?"\u2705":i.status==="warning"?"\u26A0\uFE0F":"\u274C"}),s("div",{children:[n("div",{style:{fontSize:"14px",fontWeight:700,marginBottom:"2px"},children:i.label}),n("div",{style:{fontSize:"12px",color:"#6b7280"},children:i.message})]})]},i.id))})]},e.title))]}),E==="edit"&&n("div",{style:{maxWidth:"650px"},children:s("div",{style:{background:"#fff",padding:"32px",borderRadius:"15px",border:"1px solid #e5e7eb",boxShadow:"0 1px 3px rgba(0,0,0,0.05)"},children:[s("div",{style:{marginBottom:"24px"},children:[n("label",{style:{display:"block",fontSize:"13px",fontWeight:800,color:"#374151",marginBottom:"8px"},children:"SEO Title"}),n("input",{style:{width:"100%",padding:"12px 16px",borderRadius:"10px",border:"1px solid #d1d5db",fontSize:"15px",outline:"none"},value:C,onChange:e=>P(e.target.value)}),s("div",{style:{fontSize:"11px",marginTop:"6px",color:C.length>60?"#ef4444":"#9ca3af"},children:[C.length," / 60 characters"]})]}),s("div",{style:{marginBottom:"24px"},children:[n("label",{style:{display:"block",fontSize:"13px",fontWeight:800,color:"#374151",marginBottom:"8px"},children:"Permalink (Slug)"}),s("div",{style:{display:"flex",alignItems:"center",background:"#f3f4f6",borderRadius:"10px",padding:"0 12px",border:"1px solid #d1d5db"},children:[n("span",{style:{fontSize:"13px",color:"#9ca3af",marginRight:"4px"},children:"/"}),n("input",{style:{flex:1,background:"transparent",border:"none",padding:"12px 4px",fontSize:"15px",outline:"none"},value:j,onChange:e=>F(e.target.value.replace(/\s+/g,"-").toLowerCase())})]})]}),s("div",{style:{marginBottom:"32px"},children:[n("label",{style:{display:"block",fontSize:"13px",fontWeight:800,color:"#374151",marginBottom:"8px"},children:"Meta Description"}),n("textarea",{style:{width:"100%",padding:"12px 16px",borderRadius:"10px",border:"1px solid #d1d5db",fontSize:"15px",minHeight:"120px",outline:"none",resize:"vertical"},value:T,onChange:e=>N(e.target.value)}),s("div",{style:{fontSize:"11px",marginTop:"6px",color:T.length>160?"#ef4444":"#9ca3af"},children:[T.length," / 160 characters"]})]}),n("div",{style:{display:"flex",justifyContent:"flex-end",gap:"12px"},children:n("button",{onClick:ee,style:{padding:"12px 24px",background:"#2563eb",color:"white",border:"none",borderRadius:"10px",fontWeight:700,cursor:"pointer",fontSize:"14px"},children:"Save to Project (Server-Side)"})})]})})]})]})]})]})}import X from"fs";import le from"path";function ve(r,o){try{let d=le.join(process.cwd(),"seo-overrides.json");if(!X.existsSync(d))return o;let h=JSON.parse(X.readFileSync(d,"utf-8"))[r];return h?R(O({},o),{title:h.title||o.title,description:h.description||o.description,keywords:h.keywords||o.keywords}):o}catch(d){return console.error("SEO Helper Error:",d),o}}export{ge as NextSeoChecker,ve as getSeoMetadata};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "next-seo-checker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Professional live SEO optimizer and permalink management suite for Next.js.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"dev": "next dev",
|
|
13
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --minify --clean --tsconfig tsconfig.build.json",
|
|
14
|
+
"build:next": "next build",
|
|
15
|
+
"start": "next start",
|
|
16
|
+
"lint": "eslint"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"nextjs",
|
|
20
|
+
"seo",
|
|
21
|
+
"seo-optimizer",
|
|
22
|
+
"metadata",
|
|
23
|
+
"permalink",
|
|
24
|
+
"seo-checker"
|
|
25
|
+
],
|
|
26
|
+
"author": "",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"next": ">=13.0.0",
|
|
30
|
+
"react": ">=18.0.0",
|
|
31
|
+
"react-dom": ">=18.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^20",
|
|
35
|
+
"@types/react": "^19",
|
|
36
|
+
"@types/react-dom": "^19",
|
|
37
|
+
"eslint": "^9",
|
|
38
|
+
"eslint-config-next": "16.1.1",
|
|
39
|
+
"next": "16.1.1",
|
|
40
|
+
"react": "19.2.3",
|
|
41
|
+
"react-dom": "19.2.3",
|
|
42
|
+
"tsup": "^8.3.5",
|
|
43
|
+
"typescript": "^5"
|
|
44
|
+
}
|
|
45
|
+
}
|