Skip to content

Commit

Permalink
content type for external server
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Mar 10, 2024
1 parent 8ef58d7 commit 334b54b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/reveal/revealRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class RevealRenderer {
private exporter: RevealExporter;
private utils: ObsidianUtils;


constructor(utils: ObsidianUtils) {
this.processor = utils.markdownProcessor;
this.yaml = new YamlParser(utils.getSettings());
Expand Down
33 changes: 18 additions & 15 deletions src/reveal/revealServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import path from 'path';
import { QueryString } from '../@types';

export class RevealServer {
private _server: FastifyInstance;
private readonly _port: number;
private _revealRenderer: RevealRenderer;
private filePath: string;
private _server: FastifyInstance;
private readonly _port: number;
private _revealRenderer: RevealRenderer;
private filePath: string;

constructor(utils: ObsidianUtils, port: string) {
const numPort = Number(port);
this._port = isNaN(numPort) ? 3000 : numPort;
this._revealRenderer = new RevealRenderer(utils);
this.filePath = null;
constructor(utils: ObsidianUtils, port: string) {
const numPort = Number(port);
this._port = isNaN(numPort) ? 3000 : numPort;
this._revealRenderer = new RevealRenderer(utils);
this.filePath = null;

this._server = Fastify({});
this._server.register(fastifyStatic, {
Expand All @@ -26,14 +26,17 @@ export class RevealServer {
serve: false
});

this._server.get<{Querystring: QueryString}>('/', async (request, reply) => {
this._server.get<{ Querystring: QueryString }>('/', async (request, reply) => {
if (this.filePath === null) {
reply
.type('text/html')
.send(chooseSlides);
} else {
const markup = await this._revealRenderer.renderFile(this.filePath, request.query);
reply.send(markup);
const markup = await this._revealRenderer
.renderFile(this.filePath, request.query);
reply
.type('text/html')
.send(markup);
}
return reply;
});
Expand All @@ -52,7 +55,7 @@ export class RevealServer {
});
});

this._server.get<{Querystring: QueryString}>('/*', async (request, reply) => {
this._server.get<{ Querystring: QueryString }>('/*', async (request, reply) => {
// @ts-ignore
const file = request.params['*'];

Expand All @@ -75,7 +78,7 @@ export class RevealServer {
}
return reply;
});
}
}

get running(): boolean {
return !!this._server.addresses().slice(-1).pop();
Expand All @@ -92,7 +95,7 @@ export class RevealServer {
}

private fixedEncodeURIComponent(str: string) {
return str.replace(/[!'()*]/g, function(c) {
return str.replace(/[!'()*]/g, function (c) {
return '%' + c.charCodeAt(0).toString(16);
});
}
Expand Down

0 comments on commit 334b54b

Please sign in to comment.