Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ pageMetadata: {
}
```

### Nooxy Configuration

```javascript
nooxy: {
// Show "Made with Nooxy" badge in header
// Default: true - set to false to hide the badge
showBadge: true,
}
```

### Optional Features

| Field | Description |
Expand Down
10 changes: 10 additions & 0 deletions examples/cloudflare/nooxy/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ export const SITE_CONFIG = {
// // aiAttribution: 'Your Name - example.com',
// },

// ============================================================================
// OPTIONAL: Nooxy Configuration
// ============================================================================

// nooxy: {
// // Show "Made with Nooxy" badge in header
// // Default: true - set to false to hide the badge
// showBadge: true,
// },

// ============================================================================
// ADVANCED: Custom Code Injection
// ============================================================================
Expand Down
2 changes: 1 addition & 1 deletion examples/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"wrangler": "^4.32.0"
},
"dependencies": {
"nooxy": "^1.7.1"
"nooxy": "^1.8.0"
}
}
10 changes: 10 additions & 0 deletions src/cli/templates/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ export const SITE_CONFIG = {
// // aiAttribution: 'Your Name - example.com',
// },

// ============================================================================
// OPTIONAL: Nooxy Configuration
// ============================================================================

// nooxy: {
// // Show "Made with Nooxy" badge in header
// // Default: true - set to false to hide the badge
// showBadge: true,
// },

// ============================================================================
// ADVANCED: Custom Code Injection
// ============================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/rewriters/custom/generated/_head-js-string.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const HEAD_JS_STRING = `function buildCustomHeader(customHeader){return \`<div class="nooxyBadge_4f7c2b1a-demo-topbar">\${customHeader ?? ''}<a class="nooxyBadge_4f7c2b1a-badge-link" style="cursor: pointer;" href="https://github.com/draphy/nooxy" tabindex="0" target="_blank" rel="noopener noreferrer"><!--Subtle shine effect--><span class="nooxyBadge_4f7c2b1a-badge-shine"></span><!--Sparkle icon--><svg class="nooxyBadge_4f7c2b1a-badge-icon" width="10" height="10" viewBox="0 0 24 24" fill="currentColor"><path d="M12 0l3.09 6.26L22 9.27l-6.91 3.01L12 24l-3.09-11.72L2 9.27l6.91-3.01L12 0z"/></svg>Made with Nooxy</a></div>\`;}const cusHeaderInterval=setInterval(()=>{const header=document.querySelector('header');const injectedHeader=document.querySelector('.nooxyBadge_4f7c2b1a-demo-topbar');if(header&&!injectedHeader){header.insertAdjacentHTML('afterbegin',buildCustomHeader(customHeader));clearInterval(cusHeaderInterval);}},300);function extractSlug(url){if(url.startsWith('/')){return url.split('?')[0];}try{const u=new URL(url);return u.pathname;}catch(_e){return url.split('?')[0];}}function extractPageId(input){const path=input.split('?')[0];const match=path.match(/([a-fA-F0-9]{32})(?=\\/?$)/);return match ? match[1]:'';}window.nooxy={_slugToPage:slugToPage,_pageToSlug:pageToSlug,_notionDomain:notionDomain,_myUrl:function(url){const notionUrl=url.replace(location.origin,this._notionDomain);const slug=extractSlug(notionUrl);const pageId=slugToPage[slug];if(pageId){const regex=new RegExp(\`\${slug}(?=\\\\?|$)\`);return notionUrl.replace(regex,\`/\${pageId}\`);}return notionUrl;},_yourUrl:function(url){const cDomainUrl=url.replace(this._notionDomain,location.origin);const pageId=extractPageId(cDomainUrl);const slug=pageToSlug[pageId];if(slug){return cDomainUrl.replace(new RegExp(\`(^|[^/])\\\\/[^/].*\${pageId}(?=\\\\?|$)\`),\`$1\${slug}\`);}return cDomainUrl;},href:function(){return this._myUrl(location.href);},};window.history.pushState=new Proxy(window.history.pushState,{apply:function(target,that,args){const data=args[0];const unused=args[1];const url=args[2];return Reflect.apply(target,that,[data,unused,window.nooxy._yourUrl(url)]);},});window.history.replaceState=new Proxy(window.history.replaceState,{apply:function(target,that,args){const data=args[0];const unused=args[1];const url=args[2];return Reflect.apply(target,that,[data,unused,window.nooxy._yourUrl(url)]);},});(function(){const replacedUrl=function(url){const match=/^https?:\\/\\/([^\\\\/]*)/.exec(url);const domain=match ? match[1]:'';if((domain.endsWith('notion.so')&&!domain.endsWith('msgstore.www.notion.so'))||domain.endsWith('splunkcloud.com')||domain.endsWith('statsigapi.net')){return url.replace(/^.*:(.*)\\/\\//,'/200/$1');}return url;};window.fetch=new Proxy(window.fetch,{apply:function(target,that,args){let url=args[0];const rest=Array.prototype.slice.call(args,1);url=replacedUrl(url);return Reflect.apply(target,that,[url].concat(rest));},});window.XMLHttpRequest=new Proxy(XMLHttpRequest,{construct:function(target,args){const xhr=new(Function.prototype.bind.apply(target,[null].concat(args)))();xhr.open=new Proxy(xhr.open,{apply:function(target,that,args){const method=args[0];let url=args[1];const rest=Array.prototype.slice.call(args,2);url=replacedUrl(url);return Reflect.apply(target,that,[method,url].concat(rest));},});return xhr;},});})();`;
export const HEAD_JS_STRING = `function buildCustomHeader(customHeader,showBadge){const badge=showBadge ? \`<a class="nooxyBadge_4f7c2b1a-badge-link" style="cursor: pointer;" href="https://github.com/draphy/nooxy" tabindex="0" target="_blank" rel="noopener noreferrer"><!--Subtle shine effect--><span class="nooxyBadge_4f7c2b1a-badge-shine"></span><!--Sparkle icon--><svg class="nooxyBadge_4f7c2b1a-badge-icon" width="10" height="10" viewBox="0 0 24 24" fill="currentColor"><path d="M12 0l3.09 6.26L22 9.27l-6.91 3.01L12 24l-3.09-11.72L2 9.27l6.91-3.01L12 0z"/></svg>Made with Nooxy</a>\`:'';return \`<div class="nooxyBadge_4f7c2b1a-demo-topbar">\${customHeader ?? ''}\${badge}</div>\`;}const cusHeaderInterval=setInterval(()=>{const header=document.querySelector('header');const injectedHeader=document.querySelector('.nooxyBadge_4f7c2b1a-demo-topbar');if(header&&!injectedHeader){header.insertAdjacentHTML('afterbegin',buildCustomHeader(customHeader,showBadge));clearInterval(cusHeaderInterval);}},300);function extractSlug(url){if(url.startsWith('/')){return url.split('?')[0];}try{const u=new URL(url);return u.pathname;}catch(_e){return url.split('?')[0];}}function extractPageId(input){const path=input.split('?')[0];const match=path.match(/([a-fA-F0-9]{32})(?=\\/?$)/);return match ? match[1]:'';}window.nooxy={_slugToPage:slugToPage,_pageToSlug:pageToSlug,_notionDomain:notionDomain,_myUrl:function(url){const notionUrl=url.replace(location.origin,this._notionDomain);const slug=extractSlug(notionUrl);const pageId=slugToPage[slug];if(pageId){const regex=new RegExp(\`\${slug}(?=\\\\?|$)\`);return notionUrl.replace(regex,\`/\${pageId}\`);}return notionUrl;},_yourUrl:function(url){const cDomainUrl=url.replace(this._notionDomain,location.origin);const pageId=extractPageId(cDomainUrl);const slug=pageToSlug[pageId];if(slug){return cDomainUrl.replace(new RegExp(\`(^|[^/])\\\\/[^/].*\${pageId}(?=\\\\?|$)\`),\`$1\${slug}\`);}return cDomainUrl;},href:function(){return this._myUrl(location.href);},};window.history.pushState=new Proxy(window.history.pushState,{apply:function(target,that,args){const data=args[0];const unused=args[1];const url=args[2];return Reflect.apply(target,that,[data,unused,window.nooxy._yourUrl(url)]);},});window.history.replaceState=new Proxy(window.history.replaceState,{apply:function(target,that,args){const data=args[0];const unused=args[1];const url=args[2];return Reflect.apply(target,that,[data,unused,window.nooxy._yourUrl(url)]);},});(function(){const replacedUrl=function(url){const match=/^https?:\\/\\/([^\\\\/]*)/.exec(url);const domain=match ? match[1]:'';if((domain.endsWith('notion.so')&&!domain.endsWith('msgstore.www.notion.so'))||domain.endsWith('splunkcloud.com')||domain.endsWith('statsigapi.net')){return url.replace(/^.*:(.*)\\/\\//,'/200/$1');}return url;};window.fetch=new Proxy(window.fetch,{apply:function(target,that,args){let url=args[0];const rest=Array.prototype.slice.call(args,1);url=replacedUrl(url);return Reflect.apply(target,that,[url].concat(rest));},});window.XMLHttpRequest=new Proxy(XMLHttpRequest,{construct:function(target,args){const xhr=new(Function.prototype.bind.apply(target,[null].concat(args)))();xhr.open=new Proxy(xhr.open,{apply:function(target,that,args){const method=args[0];let url=args[1];const rest=Array.prototype.slice.call(args,2);url=replacedUrl(url);return Reflect.apply(target,that,[method,url].concat(rest));},});return xhr;},});})();`;
17 changes: 10 additions & 7 deletions src/rewriters/custom/head.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
function buildCustomHeader(customHeader) {
return `
<div class="nooxyBadge_4f7c2b1a-demo-topbar">
${customHeader ?? ''}
<a class="nooxyBadge_4f7c2b1a-badge-link" style="cursor: pointer;" href="https://github.com/draphy/nooxy" tabindex="0" target="_blank" rel="noopener noreferrer">
function buildCustomHeader(customHeader, showBadge) {
const badge = showBadge
? `<a class="nooxyBadge_4f7c2b1a-badge-link" style="cursor: pointer;" href="https://github.com/draphy/nooxy" tabindex="0" target="_blank" rel="noopener noreferrer">
<!-- Subtle shine effect -->
<span class="nooxyBadge_4f7c2b1a-badge-shine"></span>
<!-- Sparkle icon -->
Expand All @@ -18,7 +16,12 @@ function buildCustomHeader(customHeader) {
/>
</svg>
Made with Nooxy
</a>
</a>`
: '';
return `
<div class="nooxyBadge_4f7c2b1a-demo-topbar">
${customHeader ?? ''}
${badge}
</div>
`;
}
Expand All @@ -28,7 +31,7 @@ const cusHeaderInterval = setInterval(() => {
const injectedHeader = document.querySelector('.nooxyBadge_4f7c2b1a-demo-topbar');

if (header && !injectedHeader) {
header.insertAdjacentHTML('afterbegin', buildCustomHeader(customHeader));
header.insertAdjacentHTML('afterbegin', buildCustomHeader(customHeader, showBadge));
clearInterval(cusHeaderInterval);
}
}, 300);
Expand Down
4 changes: 3 additions & 1 deletion src/rewriters/data-rewriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ export function modifyResponseData(
customBodyJS,
googleFont,
seo,
nooxy,
} = siteConfig;
let data = responseData;
const notionDomainUrl = new URL(ensureHttpsUrl(notionDomain)).origin;

const targetDomain = seo?.canonicalDomain || domain;
const safeCustomHeader = escapeForJS(customHeader || '');
const customJSCode = `var notionDomain='${notionDomainUrl}',slugToPage=${JSON.stringify(slugToPage)},pageToSlug=${JSON.stringify(pageToSlug)},customHeader='${safeCustomHeader}';${HEAD_JS_STRING}`;
const showBadge = nooxy?.showBadge !== false; // Default: true
const customJSCode = `var notionDomain='${notionDomainUrl}',slugToPage=${JSON.stringify(slugToPage)},pageToSlug=${JSON.stringify(pageToSlug)},customHeader='${safeCustomHeader}',showBadge=${showBadge};${HEAD_JS_STRING}`;
const googleFontInject = googleFont
? `<link href='https://fonts.googleapis.com/css?family=${googleFont.replace(
/ /g,
Expand Down
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,21 @@ export interface NooxySiteConfigFull {
// SEO configuration
seo?: NooxySeoConfig

// Nooxy-specific configuration
nooxy?: NooxyConfig

// Calculated fields
pageToSlug: Record<string, string>
slugs: Array<string>
}

// Nooxy-specific configuration
export interface NooxyConfig {
// Show "Made with Nooxy" badge in header
// Default: true
showBadge?: boolean
}

// SEO configuration
export interface NooxySeoConfig {
// Enable search engine indexing (removes noindex, adds canonical URL, adds robots meta)
Expand Down