rosscdh/mkdocs-markdownextradata-plugin

Macro in included page

xtran3 opened this issue · 23 comments

Could someone help me on this issue?

I have project structure like this:

  • Showcase
    Showcase.md
    • Cases
      Case1.md
  • images
    image1.PNG

mkdocs.yml file:

...
extra:
  site:
    image_path: 'http://abc/images/'
plugins:
  - search
  - git-revision-date
  - macros
  - markdownextradata
...

Showcase.md content:

{!Showcase/Cases/Case1.md!}

Case1.md content:

![SampleImage]({{ site.image_path }}image1.PNG)

If I go to http://abc/Showcase/Cases/Case1, then I can see the image1.PNG. The real url is http://abc/images/image1.PNG.
But if I go to http://abc/Showcase/Cases, the image load failed. I check the HTML source:
<img alt="SampleImage" src="{{ site.image_path }}image1.PNG">
The {{ site.image_path }} is not generated!
It seems like the macro does not work when using "include" page in .md

Could you please help to verify this?

You may need to provide more info

site_name: My Docs
nav:
    - Home: index.md
extra:
  site:
    image_path: https://via.placeholder.com/
plugins:
  - search
  - markdownextradata
# Welcome to MkDocs

For full documentation visit [mkdocs.org](https://mkdocs.org).

## Image test

![SampleImage]({{ site.image_path }}350x150)

Screen Shot 2019-04-12 at 21 06 29

Seems to work jsut fine..

I am ot using your macro plugins etc.. so please provide a full example for that?

Given that the issue appears to lie with the macros plugin? (seems to) perhaps best to lodge a ticket with them? Ill take a look as well.. but it appears to work on my side?

Now rereading the text in the bug.. yes using include does not run the internal text thought the mdocs parser so wont actually render the variables used within.

if you can provide the code you are using to generate the http://abc/Showcase/Cases page i can help you out

Hi @rosscdh ,

Thanks for your time look into my issue.

This is the code for the relating part:
WMAI.github.dxc.com.zip

The image in here works fine: https://github.dxc.com/pages/WMAI/Showcase/Intune_Modern_Management/Intune_Demo_Overview/
The image's link here is not generated: https://github.dxc.com/pages/WMAI/Showcase/Showcase/

Do you have any updates on this @rosscdh ?

Hmm just took a look..

have you debugged the output of the image?

http head https://github.dxc.com/pages/WMAI/images/modernmanagement/ModernDeviceManagement.PNG            rosscdh@s
HTTP/1.1 302 Found
Cache-Control: no-cache
Content-Security-Policy: default-src 'none'; base-uri 'self'; block-all-mixed-content; connect-src 'self' github.dxc.com www.githubstatus.com wss://github.dxc.com; font-src 'self'; form-action 'self' github.dxc.com; frame-ancestors 'none'; frame-src 'self'; img-src * data:; manifest-src 'self'; media-src 'none'; script-src 'self'; style-src 'unsafe-inline' 'self'

gives 302 looks like some kind of security... the image does not exist which is why its not being shown.

ive tried it with an existing image..... and it appears to work as expected.. there is something wrong with the image you are trying to reference....

Screen_Shot_2019-04-19_at_18_20_48

closing the issue

Hi,

Why do you close the ticket so soon? :)

You cannot see the image because you don't have permission to view it. I logged in and I can see the image at https://github.dxc.com/pages/WMAI/images/modernmanagement/ModernDeviceManagement.PNG
image

This is my issue on the including page:
image

While the included page work well:
image

Could you please share the source code of the page you are showing? Could you please share the link of the page so I can inspect the HTML source? Does your working image using macro? I would be great if you can share back to me the page you are demoing?

Many thanks

working-Archive.zip

There you go, a couple of tips

  1. its yaml you dont and indeed SHOULDNT wrap all your image references in `` or '' this has a specific case and you should study when to use this
  2. your paths should not end on a / in yaml.. its better to include the / in the path ie.. {{ site.image_path }}/whatever.PNG
  3. ALWAYS lowercase filenames
  4. image_path is actually a bad name its not a path its a image_base_url a path is the /path/to/file.png
  5. look for test_path in the modern showcase

best of luck

please note as per your last set of provision.. the pluging that does not seem to be working for you is the "macros" plugin please raise it with the maintainer.

Hi,
Much appreciate that you response to me promptly while you are in holiday vacation.
I will try your recommendation.

I tried the package you gave me and built on local. I got this error:
image

And this is the HTML source:
image

On local, I run these commands:

  		  python -m pip install --upgrade --ignore-installed pip
  		  pip --version
  		  pip install mkdocs
  		  pip install mkdocs-material
  		  pip install markdown-include
  		  pip install mkdocs-macros-plugin
  		  pip install mkdocs-git-revision-date-plugin
  		  pip install mkdocs-markdownextradata-plugin

then run "mkdocs build"
Am I correct?

as you can see the build log: the test_path is in mkdocs.yml
image

And this is the built result \site\Showcase\Showcase\index.html


<p><img alt="ModernDeviceManagement" src="{{ site.image_path }}modernmanagement/ModernDeviceManagement.PNG" /></p>
<p><img alt="ModernDeviceManagement" src="{{ site.test_path }}/funny-game-of-thrones-memes-fb__700.jpg" /></p>

I think issue has to be reopen cause focus is wrong.

Problem can replicate when you try to get macros plugin and markdown-include extension (or whatever using jinja2) work together.

It doesn matter if you use an URL (pointing to web or to an image) or a simple string.

I agree with @cesaremorel , this issue can be replicated with any value that you want to replace in a markdown partial. I think this should be reopen.