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

i18n_subsites: Generate symbolic links for specified directories in language subdirectories #1347

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,9 @@
[submodule "similar_posts"]
path = similar_posts
url = https://github.com/davidlesieur/similar_posts.git
[submodule "business_cards"]
path = business_cards
url = https://github.com/native2k/pelican.plugins.business_cards.git
[submodule "qr_code"]
path = qr_code
url = https://github.com/native2k/pelican.plugins.qr_code.git
1 change: 1 addition & 0 deletions business_cards
Submodule business_cards added at 238d89
27 changes: 27 additions & 0 deletions i18n_subsites/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dictionary must be given (but can be empty) in the ``I18N_SUBSITES`` dictionary
You must also have the following in your pelican configuration

.. code-block:: python

JINJA_ENVIRONMENT = {
'extensions': ['jinja2.ext.i18n'],
}
Expand Down Expand Up @@ -145,6 +146,32 @@ to link to the main site.
This short `howto <./implementing_language_buttons.rst>`_ shows two
example implementations of language buttons.

Additional config option
........................

If you use plugins like ``photos``, ``thumbnailer`` and want to prevent
the system from copying the files into each language directory, it is possible
to set a list of directories in the variable ``I18N_LINK_DIRS``.
For each path a symbolic link is created which links to the original directory.

.. code-block:: python

I18N_LINK_DIRS = ['images/thumbnails', 'photos']

.. code-block::

└── output/ # base output directory
├── images/
│ └── thumbnails/ # original directory
├── photos/ # original directory
└─── de/ # language subfolder
├── photos -> /output/photos # symbolic link to original directory
└── images/
└── thumbnails -> /output/images/thumbnails # symbolic link to original directory




Usage notes
===========
- It is **mandatory** to specify ``lang`` metadata for each article
Expand Down
32 changes: 32 additions & 0 deletions i18n_subsites/i18n_subsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,36 @@ def get_pelican_cls(settings):
return cls


def create_dirs(settings):
dirs = settings.get('I18N_LINK_DIRS') or []
if not dirs:
return

toutput = settings['OUTPUT_PATH']
soutput = os.path.split(toutput)[0]

_LOGGER.debug("create dirs {} in '{}' ".format(dirs, toutput))

if not os.path.exists(toutput):
os.makedirs(toutput)

for dir in dirs:
src=os.path.join(soutput, dir)
if not os.path.exists(src):
os.makedirs(src)

destpath = os.path.split(dir)[0]
if destpath:
destpathloc = os.path.join(toutput, destpath)
if not os.path.exists(destpathloc):
os.makedirs(destpathloc)

dest=os.path.join(toutput, dir)
if not os.path.exists(dest):
_LOGGER.debug(" create link '{}' -> '{}'".format(dest, src))
os.symlink(src, dest)


def create_next_subsite(pelican_obj):
'''Create the next subsite using the lang-specific config

Expand Down Expand Up @@ -433,6 +463,8 @@ def create_next_subsite(pelican_obj):
new_pelican_obj = cls(settings)
_LOGGER.debug(("Generating i18n subsite for language '{}' "
"using class {}").format(lang, cls))

create_dirs(settings)
new_pelican_obj.run()


Expand Down
3 changes: 3 additions & 0 deletions i18n_subsites/test_i18n_subsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def test_sites_generation(self):
'OUTPUT_PATH': self.temp_path,
'CACHE_PATH': self.temp_cache,
'PLUGINS': [i18ns],
'JINJA_ENVIRONMENT' : {
'extensions': ['jinja2.ext.i18n'],
},
}
)
pelican = Pelican(settings)
Expand Down
17 changes: 16 additions & 1 deletion photos/photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
ispiexif = True
logger.debug('piexif found.')

try:
import pyheif
except ImportError:
isheif = False
logger.error('pyheif not found! HEIC files not supported')
else:
isheif = True
logger.debug('pyheif found.')

def initialized(pelican):
p = os.path.expanduser('~/Pictures')
Expand Down Expand Up @@ -251,7 +259,14 @@ def manipulate_exif(img, settings):

def resize_worker(orig, resized, spec, settings):
logger.info('photos: make photo {} -> {}'.format(orig, resized))
im = Image.open(orig)
if isheif and orig.upper().endswith('.HEIC'):
with open(orig, 'rb') as file:
image = pyheif.read_heif(file)
im = Image.frombytes(
mode=image.mode, size=image.size, data=image.data)
else:
im = Image.open(orig)
im = ImageOps.exif_transpose(im)

if ispiexif and settings['PHOTO_EXIF_KEEP'] and im.format == 'JPEG': # Only works with JPEG exif for sure.
try:
Expand Down
1 change: 1 addition & 0 deletions photos/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Pillow
piexif>=1.0.5
pyheif
1 change: 1 addition & 0 deletions qr_code
Submodule qr_code added at 6537bb