-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
1 lines (1 loc) · 6.69 KB
/
index.js
1
(function(){"use strict";const e=window.Vue;function S(){return window.panel}function j(){return S().api}const L=()=>window.panel.plugins.viewButtons!==void 0;function O(){const s=S().app.$store;return s||new Proxy({},{get(){throw new Error("Vuex store is not available. Are you using Kirby 5? Use the `useContent` composable instead.")}})}function M(){const s=S(),n=O(),t=L(),o=h(t?()=>s.view.props.content:()=>n.getters["content/values"]()),c=h(t?()=>s.content.changes():()=>n.getters["content/changes"]()),d=h(t?()=>Object.keys(c.value).length>0:()=>n.getters["content/hasChanges"]()),f=t?s.content:new Proxy({},{get(){return()=>{}}});return{content:f,currentContent:o,contentChanges:c,hasChanges:d,update:async(r,k=!0)=>{if(!t&&r)for(const[l,p]of Object.entries(r))n.dispatch("content/update",[l,p]);const g=f.merge(r);k&&await f.save(g)}}}function B(){const s=j();return{load:({parent:t,name:o})=>s.get(`${t}/sections/${o}`)}}const h=e.computed;e.customRef,e.defineAsyncComponent,e.defineComponent,e.effectScope,e.getCurrentInstance,e.getCurrentScope,e.h,e.inject,e.isProxy,e.isReactive,e.isReadonly,e.isRef,e.isShallow,e.markRaw,e.nextTick,e.onActivated,e.onBeforeMount,e.onBeforeUnmount,e.onBeforeUpdate,e.onDeactivated,e.onErrorCaptured,e.onMounted,e.onRenderTracked,e.onRenderTriggered,e.onScopeDispose,e.onServerPrefetch,e.onUnmounted,e.onUpdated,e.provide,e.proxyRefs,e.reactive,e.readonly;const u=e.ref;e.shallowReactive,e.shallowReadonly,e.shallowRef,e.toRaw,e.toRef,e.toRefs,e.triggerRef,e.unref,e.useAttrs,e.useCssModule,e.useCssVars,e.useListeners,e.useSlots;const U=e.watch;e.watchEffect,e.watchPostEffect,e.watchSyncEffect;const V={blueprint:String,lock:[Boolean,Object],help:String,name:String,parent:String,timestamp:Number};class $ extends Error{constructor(){super("Throttled function aborted"),this.name="AbortError"}}function q({limit:s,interval:n,strict:t,onDelay:o}){if(!Number.isFinite(s))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(n))throw new TypeError("Expected `interval` to be a finite number");const c=new Map;let d=0,f=0;function m(){const l=Date.now();return l-d>n?(f=1,d=l,0):(f<s?f++:(d+=n,f=1),d-l)}const r=[];function k(){const l=Date.now();if(r.length>0&&l-r.at(-1)>n&&(r.length=0),r.length<s)return r.push(l),0;const p=r[0]+n;return r.shift(),r.push(p),Math.max(0,p-l)}const g=t?k:m;return l=>{const p=function(...v){if(!p.isEnabled)return(async()=>l.apply(this,v))();let _;return new Promise((b,y)=>{const x=()=>{b(l.apply(this,v)),c.delete(_)},C=g();C>0?(_=setTimeout(x,C),c.set(_,y),o==null||o(...v)):x()})};return p.abort=()=>{for(const v of c.keys())clearTimeout(v),c.get(v)(new $);c.clear(),r.splice(0,r.length)},p.isEnabled=!0,Object.defineProperty(p,"queueSize",{get(){return c.size}}),p}}const z=/^\.?\//;function G(s="",n){return s.endsWith("/")?s:s+"/"}function W(s){return s&&s!=="/"}function H(s,...n){let t=s||"";for(const o of n.filter(c=>W(c)))if(t){const c=o.replace(z,"");t=G(t)+c}else t=o;return t}function J(s,n,t,o,c,d,f,m){var r=typeof s=="function"?s.options:s;return n&&(r.render=n,r.staticRenderFns=t,r._compiled=!0),r._scopeId="data-v-"+d,{exports:s,options:r}}const A={...V},Q=Object.assign({inheritAttrs:!1},{__name:"SerpPreview",props:A,setup(s){const n=s,t=S(),o=j(),{load:c}=B(),d=u(),f=u(),m=u(),r=u(),k=u(),g=u(),l=u(),p=u(),v=u(),_=u(),b=u(),y=u(""),x=u(""),C=u(""),{currentContent:R}=M(),te=h(()=>y.value?new URL(y.value).pathname:""),D=h(()=>R.value[g.value]||l.value||[t.view.title,k.value,m.value].join(" ")),N=h(()=>(p.value?R.value[p.value]:void 0)||v.value);U(()=>t.language.code,()=>{P()});const T=q({limit:1,interval:250}),F=T(async a=>{x.value=await E("title",a)}),I=T(async a=>{C.value=await E("description",a)});U(D,a=>{var i,w;(w=(i=b.value)==null?void 0:i.formatters)!=null&&w.title&&F(a)}),U(N,a=>{var i,w;(w=(i=b.value)==null?void 0:i.formatters)!=null&&w.description&&I(a)}),P(!0);async function P(a=!1){const i=await c({parent:n.parent,name:n.name});a&&(d.value=K(i.label)||t.t("johannschopplich.serp-preview.label"),g.value=i.titleContentKey,p.value=i.descriptionContentKey,b.value=i.config,_.value=i.searchConsoleUrl),f.value=i.faviconUrl,m.value=i.siteTitle,r.value=i.siteUrl,k.value=i.titleSeparator,l.value=i.defaultTitle,v.value=i.defaultDescription;const w=await t.api.get(t.view.path,{select:"previewUrl"});y.value=w.previewUrl}function K(a){return!a||typeof a=="string"?a:a[t.translation.code]??Object.values(a)[0]}async function E(a,i){const w=t.view.path.startsWith("pages/")?t.view.path.slice(6).replaceAll("+","/"):void 0,{text:ne}=await o.post(`__serp-preview__/format/${a}`,{pageId:w,value:i});return ne}return{__sfc:!0,propsDefinition:A,props:n,panel:t,api:o,load:c,label:d,faviconUrl:f,siteTitle:m,siteUrl:r,titleSeparator:k,titleContentKey:g,defaultTitle:l,descriptionContentKey:p,defaultDescription:v,searchConsoleUrl:_,config:b,previewUrl:y,titleProxy:x,descriptionProxy:C,currentContent:R,path:te,title:D,description:N,throttle:T,throttledFormatTitle:F,throttledFormatDescription:I,updateSectionData:P,t:K,formatProperty:E,joinURL:H}}});var X=function(){var n=this,t=n._self._c,o=n._self._setupProxy;return t("k-section",{staticClass:"k-serp-section",attrs:{label:o.label}},[t("div",{staticClass:"ksp-overflow-hidden ksp-rounded-[var(--input-rounded)] ksp-bg-[var(--input-color-back)] ksp-p-4"},[t("div",{staticClass:"ksp-mb-2 ksp-flex ksp-items-center ksp-gap-3"},[o.faviconUrl?t("figure",{staticClass:"ksp-inline-flex ksp-aspect-square ksp-h-[26px] ksp-w-[26px] ksp-items-center ksp-justify-center ksp-rounded-full ksp-border ksp-border-solid ksp-border-[var(--serp-favicon-border)] ksp-bg-[var(--serp-favicon-background)]"},[t("img",{staticClass:"ksp-block ksp-h-[18px] ksp-w-[18px]",attrs:{src:o.faviconUrl,alt:""}})]):n._e(),t("div",{staticClass:"ksp-flex ksp-flex-col"},[t("span",{staticClass:"ksp-text-sm ksp-text-[var(--serp-color-text)]"},[n._v(n._s(o.siteTitle))]),t("span",{staticClass:"ksp-line-clamp-1 ksp-text-xs ksp-text-[var(--serp-color-text)]"},[n._v(n._s(o.joinURL(o.siteUrl,o.path)))])])]),t("h3",{staticClass:"ksp-line-clamp-1 ksp-text-xl ksp-text-[var(--serp-color-title)]"},[n._v(" "+n._s(o.titleProxy||o.title)+" ")]),t("p",{directives:[{name:"show",rawName:"v-show",value:o.description,expression:"description"}],staticClass:"ksp-mt-1 ksp-line-clamp-2 ksp-text-sm ksp-text-[var(--serp-color-text)]"},[n._v(" "+n._s(o.descriptionProxy||o.description)+" ")])]),t("k-button-group",{directives:[{name:"show",rawName:"v-show",value:o.searchConsoleUrl,expression:"searchConsoleUrl"}],staticClass:"ksp-mt-2 ksp-w-full"},[t("k-button",{attrs:{link:o.searchConsoleUrl,icon:"open",target:"_blank"}},[n._v(" Google Search Console ")])],1)],1)},Y=[],Z=J(Q,X,Y,!1,null,"9d9f1259");const ee=Z.exports;window.panel.plugin("johannschopplich/serp-preview",{sections:{"serp-preview":ee}})})();