Giter Site home page Giter Site logo

Comments (6)

timvink avatar timvink commented on June 12, 2024

Can you try using an absolute URL like (notice the / in front of the path):

- print-site:
      path_to_pdf: "/tmp/12345/document.pdf"

from mkdocs-print-site-plugin.

timvink avatar timvink commented on June 12, 2024

Alternatively, if you mean the tmp folder is in your git repostory on the save level as docs , you could try ../tmp/12345/document.pdf .

In the code, a relative URL is determined from the page URL:

# Link to the PDF version of the entire site on a page.
if self.config.get("path_to_pdf") != "":
page.url_to_pdf = get_relative_url(
self.config.get("path_to_pdf"), page.file.url
)

from mkdocs-print-site-plugin.

liya2017 avatar liya2017 commented on June 12, 2024

Alternatively, if you mean the tmp folder is in your git repostory on the save level as docs , you could try ../tmp/12345/document.pdf .

I tried it,and my project look like this

│└─ docs
│└─ assets
│ └─ document.pdf
└─ mkdocs.yml

I tried

- print-site:
      path_to_pdf: "../assets/document.pdf"

also tried

- print-site:
      path_to_pdf: "/User/xxx/project_name/assets/document.pdf"

from mkdocs-print-site-plugin.

timvink avatar timvink commented on June 12, 2024

I see. It has to do with the get_relative_url() function, (from mkdocs.utils):

def get_relative_url(url: str, other: str) -> str:
    """
    Return given url relative to other.
    Both are operated as slash-separated paths, similarly to the 'path' part of a URL.
    The last component of `other` is skipped if it contains a dot (considered a file).
    Actual URLs (with schemas etc.) aren't supported. The leading slash is ignored.
    Paths are normalized ('..' works as parent directory), but going higher than the
    root has no effect ('foo/../../bar' ends up just as 'bar').
    """
    ...

https://github.com/mkdocs/mkdocs/blob/56b235a8ad43f2300d17f87e6fa4de7a3d764397/mkdocs/utils/__init__.py#L267-L276

So mkdocs is expecting assets to be either a URL or inside the project.

One solution could be to use the new mkdocs 1.4 hooks feature. Pseudo code:

  1. Add a script like scripts/move_assets.py with
import shutil
from pathlib import Path
def on_startup(*args, **kwargs):
    dst_path = "docs/assets/pdfs"
    Path(dst_path).mkdirs(exist_ok=True)
    shutil.copy("your folder location of PDF", dst_path)
  1. Update mkdocs.yml with:
hooks:
    - scripts/move_assets.py
  1. Update your .gitignore file:
echo "docs/assets/pdfs/" >> .gitignore

from mkdocs-print-site-plugin.

liya2017 avatar liya2017 commented on June 12, 2024

ah,thanks for your support, will try it later.

from mkdocs-print-site-plugin.

timvink avatar timvink commented on June 12, 2024

Closing this issue, as any assets always need to be inside the docs/ folder.

There is a separate issue when using external URLs with path_to_pdf, for which I will release a fix soon

from mkdocs-print-site-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.