diff --git a/docs/assets/article.min.js b/docs/assets/article.min.js index 4bee295..822b60d 100644 --- a/docs/assets/article.min.js +++ b/docs/assets/article.min.js @@ -1 +1 @@ -import{IDateComponentElement}from"./i-date.min.js";class ArticleTagsApp{constructor(){}id="";set_id(){const t=location.pathname.split("articles/")[1];t&&(this.id=t.split(".")[0])}responsed_source_data={};get data_api_path(){return location.host.includes("127.0.0.1")?"/docs/assets/stub-data-api.json":`https://iigmir.serv00.net/api/blog-metadata.php/${this.id}`}get ajax_data(){return this.responsed_source_data.data}tags_data=[];get tags_api_path(){return location.host.includes("127.0.0.1")?"/docs/assets/stub-tag-api.json":"https://raw.githubusercontent.com/iigmir/blog-source/master/info-files/categories.json"}get matched_tags(){return[...(this.responsed_source_data.data??{category_id:[]}).category_id].map((t=>this.tags_data.find((e=>e.id===t))?.tag_name??null)).filter((t=>t))}request_api(){return new Promise(((t,e)=>{this.id||e("No ID given");Promise.all([fetch(this.tags_api_path).then((t=>t.json())),fetch(this.data_api_path).then((t=>t.json()))]).then((([e,a])=>{this.tags_data=e,this.responsed_source_data=a,t(this.responsed_source_data)}))}))}}class ArticleTagsAppELement extends HTMLElement{tags_object=null;constructor(){super()}connectedCallback(){this.tags_object=new ArticleTagsApp,this.tagsapp_action()}tagsapp_action(){this.tags_object.set_id(),this.tags_object.request_api().then((t=>{this.render_element()})).catch((t=>{console.error(t)}))}render_element(){const t=this.tags_object,e=this.attachShadow({mode:"open"}),a=document.createElement("footer");a.setAttribute("class","tags container");const s=document.createElement("p");s.textContent="Tags: ";const n=document.createElement("ul");n.classList.add("badges"),n.classList.add("-round");t.matched_tags.map((t=>{const e=document.createElement("li");return e.classList.add("item"),e.classList.add("click-icon"),e.textContent=t,e})).forEach((t=>n.appendChild(t)));const i=document.createElement("link");i.setAttribute("rel","stylesheet"),i.setAttribute("href","../css/new-framework.min.css");const d=document.createElement("span");d.textContent=" ",e.appendChild(i),e.appendChild(a),a.appendChild(this.generate_date_component("Created: ","date -created",t.ajax_data.created_at)),a.appendChild(d),a.appendChild(this.generate_date_component("Updated: ","date -updated",t.ajax_data.updated_at)),a.appendChild(s),a.appendChild(n)}generate_date_component(t="",e="",a=""){const s=document.createElement("i-date");return s.dataset.title=t,s.dataset.date=a,s.dataset.classes=e,s.dataset.timezone="Asia/Taipei",s}}function main(){customElements.define("article-tags-app",ArticleTagsAppELement),customElements.define("i-date",IDateComponentElement)}main(); \ No newline at end of file +import{IDateComponentElement}from"./i-date.min.js";class ArticleTagsApp{constructor(){}id="";set_id(){const t=location.pathname.split("articles/")[1];t&&(this.id=t.split(".")[0])}responsed_source_data={};get data_api_path(){return location.host.includes("127.0.0.1")?"/docs/assets/stub-data-api.json":`https://iigmir.serv00.net/api/blog-metadata/${this.id}`}get ajax_data(){return this.responsed_source_data.data}tags_data=[];get tags_api_path(){return location.host.includes("127.0.0.1")?"/docs/assets/stub-tag-api.json":"https://raw.githubusercontent.com/iigmir/blog-source/master/info-files/categories.json"}get matched_tags(){return[...(this.responsed_source_data.data??{category_id:[]}).category_id].map((t=>this.tags_data.find((e=>e.id===t))?.tag_name??null)).filter((t=>t))}request_api(){return new Promise(((t,e)=>{this.id||e("No ID given");Promise.all([fetch(this.tags_api_path).then((t=>t.json())),fetch(this.data_api_path).then((t=>t.json()))]).then((([e,a])=>{this.tags_data=e,this.responsed_source_data=a,t(this.responsed_source_data)})).catch((t=>{e(t)}))}))}}class ArticleTagsAppELement extends HTMLElement{tags_object=null;constructor(){super()}connectedCallback(){this.tags_object=new ArticleTagsApp,this.tagsapp_action()}tagsapp_action(){this.tags_object.set_id(),this.tags_object.request_api().then((t=>{this.render_resolved_element()})).catch((t=>{console.error(t),this.render_rejected_element(t)}))}render_resolved_element(){const t=this.tags_object,e=this.attachShadow({mode:"open"}),a=document.createElement("footer");a.setAttribute("class","tags container");const s=document.createElement("p");s.textContent="Tags: ";const n=document.createElement("ul");n.classList.add("badges"),n.classList.add("-round");t.matched_tags.map((t=>{const e=document.createElement("li");return e.classList.add("item"),e.classList.add("click-icon"),e.textContent=t,e})).forEach((t=>n.appendChild(t)));const d=document.createElement("link");d.setAttribute("rel","stylesheet"),d.setAttribute("href","../css/new-framework.min.css");const i=document.createElement("span");i.textContent=" ",e.appendChild(d),e.appendChild(a),a.appendChild(this.generate_date_component("Created: ","date -created",t.ajax_data.created_at)),a.appendChild(i),a.appendChild(this.generate_date_component("Updated: ","date -updated",t.ajax_data.updated_at)),a.appendChild(s),a.appendChild(n)}render_rejected_element(t=""){const e=this.attachShadow({mode:"open"}),a=document.createElement("footer");a.setAttribute("class","tags container");const s=document.createElement("link");s.setAttribute("rel","stylesheet"),s.setAttribute("href","../css/new-framework.min.css");const n=document.createElement("span");n.textContent="Oh-oh. Something's up. :-(",n.dataset.errorMessage=t,e.appendChild(s),e.appendChild(a),a.appendChild(n)}generate_date_component(t="",e="",a=""){const s=document.createElement("i-date");return s.dataset.title=t,s.dataset.date=a,s.dataset.classes=e,s.dataset.timezone="Asia/Taipei",s}}function main(){customElements.define("article-tags-app",ArticleTagsAppELement),customElements.define("i-date",IDateComponentElement)}main(); \ No newline at end of file