@etsoo/website
Version:
ETSOO CMS Based NextJs Website Framework
73 lines (72 loc) • 1.92 kB
JavaScript
import { FetchApi } from '@etsoo/restclient';
/**
* Static Site class
* 静态网站类
*/
export class StaticSite {
/**
* Constructor
* 构造函数
* @param apiUrl Headless CMS API Url
* @param token Access token
* @param scheme Scheme, default is 'ETSOOCMS', ETSOO website content management system
*/
constructor(apiUrl, token, scheme = 'ETSOOCMS') {
const api = new FetchApi();
api.baseUrl = apiUrl;
api.authorize(scheme, token);
this.api = api;
}
/**
* Get article
* 读取文章
* @param rq Request data
* @returns Result
*/
getArticle(rq) {
return this.api.post('Service/GetArticle', rq);
}
/**
* Get articles
* 读取文章列表
* @param rq Request data
* @returns Result
*/
getArticles(rq) {
return this.api.post('Service/GetArticles', rq);
}
/**
* Get slideshow articles
* 获取幻灯片文章
* @returns Result
*/
getSlideshows() {
return this.api.get('Service/GetSlideshows');
}
/**
* Get site data
* 获取网站信息
* @returns Data
*/
getSiteData() {
return this.api.get('Service/GetSiteData');
}
/**
* Get tab article
* 获取栏目文章
* @param siteData Site data
* @param tabName Tab name
* @param tabUrl Tab URL
* @param withContent Include article content
* @returns Result
*/
async getTabArticle(siteData, tabName, tabUrl, withContent) {
// Default tab URL
tabUrl !== null && tabUrl !== void 0 ? tabUrl : (tabUrl = `/${tabName}`);
// Tab
const tab = siteData.tabs.find((tab) => tab.name.toLowerCase() === tabName || tab.url === tabUrl);
if (tab == null)
return undefined;
return await this.getArticle({ tab: tab.id, withContent });
}
}