Skip to content

Commit

Permalink
Updated docs and plugin code
Browse files Browse the repository at this point in the history
  • Loading branch information
iSOLveIT committed May 17, 2023
1 parent 9f9eeb6 commit 2c81313
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ The extension supports many advanced features such as table of contents, customi
, support for CSS paged media module `CSS paged media module <https://developer.mozilla.org/en-US/docs/Web/CSS/@page>`_
, and using Sphinx page metadata to generate cover page.

If you find Sphinx-PDF Generate useful, please consider `starring <https://github.com/iSOLveIT/sphinx-pdf-generate>`_ the project. Thank you!

Requirements
------------

Expand Down
14 changes: 12 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,21 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

:pagebreak:`True`

Changelog
---------

0.0.3
+++++

Released: **17-05-2023**

* **17/05/2023** :
* Updated docs
* Bug fixes to improve plugin
* Updated plugin log messages output

0.0.2
+++++

Expand All @@ -45,8 +57,6 @@ Released: **07-05-2023**
* Bug fixes to improve plugin
* Updated GitHub Actions workflows and noxfile.py

:pagebreak:`True`

0.0.1
+++++

Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ The extension supports many advanced features such as table of contents, customi
, support for CSS paged media module `CSS paged media module <https://developer.mozilla.org/en-US/docs/Web/CSS/@page>`_
, and using Sphinx page metadata to generate cover page.

If you find Sphinx-PDF Generate useful, please consider `starring <https://github.com/iSOLveIT/sphinx-pdf-generate>`_ the project. Thank you!

Requirements
------------

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tool.poetry]
name = "sphinx-pdf-generate"

# !! Don't miss updates in __init__.py, and changelog.rst!!!
version = "0.0.2"
# !! Don't miss updates in version.py, and changelog.rst!!!
version = "0.0.3"

description = "A Sphinx extension to generate individual PDF files for each documentation page."
authors = ["Duodu Randy <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion sphinx_pdf_generate/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def show(*, context: Optional[str] = None, command: Union[list, tuple, None] = N
_log(context, colour=Fore.CYAN)
if command is not None:
assert isinstance(command, (list, tuple))
_log("> " + " ".join(shlex.quote(s) for s in command), colour=Fore.BLUE)
_log("> " + " ".join(shlex.quote(s) for s in command), colour=Fore.MAGENTA)
if error is not None:
_log(context, colour=Fore.RED)

Expand Down
16 changes: 11 additions & 5 deletions sphinx_pdf_generate/pdf_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from sphinx.application import Sphinx
from sphinx.util import docutils

from sphinx_pdf_generate.build import show
from sphinx_pdf_generate.logging import get_logger
from sphinx_pdf_generate.options import Options
from sphinx_pdf_generate.renderer import Renderer
Expand Down Expand Up @@ -108,6 +109,10 @@ def build_finished(app: Sphinx, exception: Exception):
)

local_options = app.env.sphinx_pdfgen_data
if "genindex" in local_options:
local_options["genindex"] = {"pdf-build": "False"}
if "search" in local_options:
local_options["search"] = {"pdf-build": "False"}
pdf_metadata = {"GLOBAL_OPTIONS": global_options, "LOCAL_OPTIONS": local_options}

path_to_save_metadata = Path(app.outdir).joinpath("pdf_metadata.json")
Expand Down Expand Up @@ -188,9 +193,10 @@ def convert_page_to_pdf(self, html_content: str, pagename: str, page_metadata: D
file_name = pdf_meta.get("filename") or pdf_meta.get("title") or self._options.body_title or None
if file_name is None:
file_name = str(pagename).split("/")[-1]
self._logger.error(
f"You must set the filename metadata in {pagename}.rst so we can use in the PDF document. "
f"The source filename is used as fallback."
show(
context=f"You must set the filename metadata in {pagename}.rst so we can use in the PDF document. "
f"The source filename is used as fallback.",
error=True,
)

# Generate a secure filename
Expand All @@ -199,7 +205,7 @@ def convert_page_to_pdf(self, html_content: str, pagename: str, page_metadata: D
pdf_file = file_name + ".pdf"

try:
self._logger.info(f"Converting {src_path} to {pdf_file}")
show(context=f"Converting {src_path} to {pdf_file}")
self.renderer.write_pdf(
html_content,
base_url,
Expand All @@ -213,7 +219,7 @@ def convert_page_to_pdf(self, html_content: str, pagename: str, page_metadata: D
self.num_errors += 1
raise PDFGenerateException(f"Error converting {src_path}. Reason: {e}")
else:
self._logger.info(f"Skipped: PDF conversion for {src_path}")
show(context=f"Skipped: PDF conversion for {src_path}")

end = timer()
self.total_time += end - start
Expand Down
2 changes: 1 addition & 1 deletion sphinx_pdf_generate/preprocessor/links/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def rel_html_href(base_url: str, href: str, site_url: str, outdir: str):
replace_build_dir = re.compile(pattern)

internal = href.startswith("#")
web_url = re.search(r"^(https://|http://)", href)
web_url = re.search(r"^(https://|http://|mailto:|tel:)", href)
if web_url or internal or not is_doc(href):
return href

Expand Down
2 changes: 1 addition & 1 deletion sphinx_pdf_generate/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.2"
__version__ = "0.0.3"

0 comments on commit 2c81313

Please sign in to comment.