Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set modified time of generated pdf equal to related article #14

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions pelican/plugins/pdf/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging
import os
import re
import time

from pelican import signals
from pelican.generators import Generator
Expand Down Expand Up @@ -102,6 +103,9 @@ def _create_pdf(self, obj, output_path):

self.pdfcreator.createPdf(text=(header + text), output=output_pdf)

if obj.date is not None:
self._set_file_utime(output_pdf, obj.date)

def _get_intrasite_link_regex(self):
intrasite_link_regex = self.settings["INTRASITE_LINK_REGEX"]
regex = r"""
Expand All @@ -111,6 +115,11 @@ def _get_intrasite_link_regex(self):
)
return re.compile(regex, re.X)

def _set_file_utime(self, path, datetime):
"""Set modified time (mtime) of specified file."""
mtime = time.mktime(datetime.timetuple())
os.utime(path, (mtime, mtime))

def generate_context(self):
pass

Expand Down