| 175 | } |
| 176 | |
| 177 | async _loadFile(filePath) { |
| 178 | debug('docsify')(`load > ${filePath}`); |
| 179 | let content; |
| 180 | try { |
| 181 | if (isAbsolutePath(filePath)) { |
| 182 | const res = await fetch(filePath); |
| 183 | if (!res.ok) { |
| 184 | throw Error(); |
| 185 | } |
| 186 | |
| 187 | content = await res.text(); |
| 188 | this.lock = 0; |
| 189 | } else { |
| 190 | content = await readFileSync(filePath, 'utf8'); |
| 191 | this.lock = 0; |
| 192 | } |
| 193 | |
| 194 | return content; |
| 195 | } catch (e) { |
| 196 | this.lock = this.lock || 0; |
| 197 | if (++this.lock > 10) { |
| 198 | this.lock = 0; |
| 199 | return; |
| 200 | } |
| 201 | |
| 202 | const fileName = basename(filePath); |
| 203 | const result = await this._loadFile( |
| 204 | resolvePathname(`../${fileName}`, filePath) |
| 205 | ); |
| 206 | |
| 207 | return result; |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | Renderer.version = '__VERSION__'; |