claudioc / jingo

Node.js based Wiki
MIT License
1.02k stars 184 forks source link

Link images #31

Closed claudioc closed 9 years ago

claudioc commented 10 years ago

There should be a way to use images from inside the repository

macterra commented 9 years ago

I would be interested in working on this one if you give me a hint about how to approach it. For example, would you add Images to the models so that _getWikiPage can do something different in the case where req.params.page ends in a known image extension ('.png', 'jpg', etc)?

claudioc commented 9 years ago

Hi David, that's great news :) Give just a moment to think about it and I'll get back to you!

claudioc commented 9 years ago

The idea is to be able to make any image in the document directory available to be linked inside a document. Ideally, given a kitten.png in the doc directory, one should be able to use it as ![A kitten](kitten.png). At the moment this is impossible for obvious reasons.

I think I would approach this using a middleware. The middleware would intercept all the requests and if the requested item is an image, try to serve it right away reading it from the doc directory. The middleware would also send a 404 if the image is not readable.

To be able to read the configuration, the middleware should inherit from a Configurable class (just look for example in namer.js on how to use this).

What do you think?

macterra commented 9 years ago

OK that seems like a good approach if we're only interested in serving the most recent version of a given image. Thanks, I'll keep you posted on my progress and questions.

macterra commented 9 years ago

I have a potential fix that works by configuring the node-ecstatic middleware to serve static files from the directory specified by the repository configuration. There are a couple remaining issues.

One, it doesn't yet handle the case where docSubdir is specified. I assume I should just path.join() that with the repository if specified? Second, the ecstatic middleware will serve the .md files if requested in the browser. I assume that should be prevented and the markdown files should be hidden?

claudioc commented 9 years ago
  1. Yes. There is an helper in the gitmech library that helps you with that issue. Just use Git.absPath(yourfile) and you'll get directly the full path of the file (Git is global)
  2. Yes, it should be prevented. I guess there will be a way to give ecstatic a white list of file types/extensions to serve

:)