Skip to content

Commit

Permalink
Fix up some static assets issues
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Mar 31, 2018
1 parent 47a5df1 commit 38306fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ function getSlideOptions(yamlOptions, extraOptions) {
config.local,
config.defaults
);
options.themeUrl = (options.base + options.themeUrl).replace(/^\.http/, 'http');
return options;
}

Expand All @@ -94,7 +93,7 @@ function parseOptions(options) {
options.base = '.';
}
if (options.theme) {
options.themeUrl = parseTheme(options.theme);
options.themeUrl = parseTheme(options);
}
if (options.highlightTheme) {
options.highlightThemeUrl = '/css/highlight/' + options.highlightTheme + '.css';
Expand Down Expand Up @@ -129,15 +128,16 @@ function parsePreprocessor(preprocessor) {
return preprocessor ? require(preprocessor) : defaults.preprocessorFn;
}

function parseTheme(theme) {
function parseTheme(options) {
const { theme, static, base = '' } = options;
const parsedUrl = url.parse(theme);
if (parsedUrl.host) {
return theme;
} else {
const revealTheme = revealThemes.find(
themePath => path.basename(themePath).replace(path.extname(themePath), '') === theme
);
return '/' + revealTheme || getAssetPath(theme);
return revealTheme || base + '/' + (static ? theme : getAssetPath(theme));
}
}

Expand Down
5 changes: 1 addition & 4 deletions lib/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const { getOptions } = require('./options');

const staticDir = express.static;

const getAsset = (req, res) => res.sendFile(path.resolve(process.cwd(), req.url.replace(/^\/_assets\//, '')));

module.exports = function startServer(options, cb) {
const app = express();

Expand All @@ -36,8 +34,7 @@ module.exports = function startServer(options, cb) {

app.get(/(\w+\.md)/, renderMarkdown);

app.get('/_assets/*', getAsset);

app.use('/_assets', staticDir(process.cwd()));
app.use('/', staticDir(process.cwd()));

app.get('/*', (req, res, next) => {
Expand Down

0 comments on commit 38306fb

Please sign in to comment.