MCPcopy
hub / github.com/docsifyjs/docsify / renderToString

Method renderToString

packages/docsify-server-renderer/index.js:87–130  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

85 }
86
87 async renderToString(url) {
88 this.url = url = this.router.parse(url).path;
89 this.isRemoteUrl = isExternal(this.url);
90 const { loadSidebar, loadNavbar, coverpage } = this.config;
91
92 const mainFile = this._getPath(url);
93 this._renderHtml('main', await this._render(mainFile, 'main'));
94
95 if (loadSidebar) {
96 const name = loadSidebar === true ? '_sidebar.md' : loadSidebar;
97 const sidebarFile = this._getPath(resolve(url, `./${name}`));
98 this._renderHtml('sidebar', await this._render(sidebarFile, 'sidebar'));
99 }
100
101 if (loadNavbar) {
102 const name = loadNavbar === true ? '_navbar.md' : loadNavbar;
103 const navbarFile = this._getPath(resolve(url, `./${name}`));
104 this._renderHtml('navbar', await this._render(navbarFile, 'navbar'));
105 }
106
107 if (coverpage) {
108 let path = null;
109 if (typeof coverpage === 'string') {
110 if (url === '/') {
111 path = coverpage;
112 }
113 } else if (Array.isArray(coverpage)) {
114 path = coverpage.indexOf(url) > -1 && '_coverpage.md';
115 } else {
116 const cover = coverpage[url];
117 path = cover === true ? '_coverpage.md' : cover;
118 }
119
120 const coverFile = this._getPath(resolve(url, `./${path}`));
121
122 this._renderHtml('cover', await this._render(coverFile), 'cover');
123 }
124
125 const html = this.html;
126
127 this.html = this.template;
128
129 return html;
130 }
131
132 _renderHtml(match, content) {
133 this.html = this.html.replace(new RegExp(`<!--${match}-->`, 'g'), content);

Callers 1

server.jsFile · 0.80

Calls 5

_getPathMethod · 0.95
_renderHtmlMethod · 0.95
_renderMethod · 0.95
isExternalFunction · 0.70
parseMethod · 0.45

Tested by

no test coverage detected