(url)
| 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); |
no test coverage detected