picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.81k stars 615 forks source link

Images in content folder are not displayed #545

Closed KoljaL closed 4 years ago

KoljaL commented 4 years ago

Hi, In our project we want to display notebooks exported from Jupyter on PicoCMS. The structure of the export is always the same:

notebook.md  
notebook_files/graph.png

The image markdowncode inside the .md files looks like this: ![Png](notebook_files/graph.png).

But that's not how the graphics are displayed.

It would be possible to change all paths before uploading them, but always time-consuming. And we would like to keep the structure.

Why is pico doing this and how can we change it?

marcus-at-localhost commented 4 years ago

See https://github.com/picocms/Pico/issues/530#issuecomment-586689852

It's for security reasons, but no one keeps you from changing it:

  1. make sure .htaccess doesn't keep you from accessing the content folder content|content-sample
    # Deny access to internal dirs and files by passing the URL to Pico
    RewriteRule ^(config|content|content-sample|lib|vendor)(/|$) index.php [L]
  1. Then you have to write a plugin (http://picocms.org/development/#plugins) to expand the path in your markdown file.

Something like this:

    /**
     * Triggered after Pico has prepared the raw file contents for parsing
     *
     * @see DummyPlugin::onContentParsing()
     * @see Pico::parseFileContent()
     * @see DummyPlugin::onContentParsed()
     *
     * @param string &$markdown Markdown contents of the requested page
     *
     * @return void
     */
    public function onContentPrepared(&$markdown)
    {
        // search for image tags and expand the full path to your images in the content folder
    }

That should give you an idea.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1:

KoljaL commented 4 years ago

I went a different way. Jupyter saves the Notebook as Markdown (with nbconvert) and then embed the images as Base64 Url in the file with this js-extension: https://github.com/freeman-lab/embed-images

my last cell in every notebook looks like this:

os.system('jupyter nbconvert --to markdown ' + ipyparams.notebook_name + ' --output Markdown_Files/' + ipyparams.notebook_name[:-6] + '.md')
os.system('embed-images Markdown_Files/' + ipyparams.notebook_name[:-6] + '.md > Markdown_Files/' + ipyparams.notebook_name[:-6] + '_emb.md') 

to get the name of the notebook, this is necessary: https://pypi.org/project/ipyparams/

known issues:
if you (re)start the kernen and run the whole notebook for the first time, no file will be saved.
solution:
just run the last cell again