/*=============================================================================================
	author:ZhaoJun
	version:1.2
	email:2732810281@qq.com
=============================================================================================*/


//严格模式
/*-------------------------------------------------------------------------------------------*/	
'use strict';
/*-------------------------------------------------------------------------------------------*/

// 常用操作
/*-------------------------------------------------------------------------------------------*/	
    class seo
    {       
		static com(df,data)
		{
			var fs=require('fs')
			return new Promise
			(
				function(reslove)
				{
					fs.readFile
					(
						df,{encoding:'utf8'},function(err,str)
						{
							if(err)
							{
								reslove('');
								console.error("[seo文件]"+df+'------错误------'+'描述:'+err.stack);
							}
							else
							{
								reslove($Sys.model('/http/render','display',[str,data]))
							}
						}
					)
				}
			)
        }
        
		static index(data)
		{
            data={title:'',descript:'',kw:'',h1:'',strong:'',content:'',footer:'',href:{link:'',param:{}},...data};
            const query=require('querystring');
            if(data.href instanceof Object)
            {
                if(data.href.param)
                {
                    if(data.href.param.route instanceof Object)data.href.param.route=
                        Buffer.from(JSON.stringify(data.href.param.route)).toString('base64');
                    if(data.href.param.routeRely instanceof Object)data.href.param.routeRely=
                        Buffer.from(JSON.stringify(data.href.param.routeRely)).toString('base64');
                }
                else
                {
                    data.href.param='';
                }
                data.href=data.href.link+'?'+query.stringify(data.href.param)
            }
			let df=$Config.root+$Config.seo
			return seo.com(df,data);
        }
        
		static list(data)
		{
            data=
            {
                title:'',descript:'',kw:'',
                list:[{title:'默认',href:'/'}],
                seoList:'/seoList?page=',
                page:2,href:'/',
                ...data
            };

            let str=''
            let str1=''
            for (let index = 0; index < data.page; index++) 
            {
                str+=`<a href='${data.seoList}${index}'>${index}</a>`;
            }
            for (let index = 0; index < data.list.length; index++) 
            {
                str1+=`<a href='${data.list[index].href}' title='data.list[index].title'>${data.list[index].title}</a>`;
            }
            data.page=str;
            data.list=str1;
            
			let df=$Config.root+$Config.seoList
			return seo.com(df,data);
		}
    }
/*-------------------------------------------------------------------------------------------*/   
    
module.exports=seo;