mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Don't rewrite URLs
Remove the code that was appending ../static in front of some URLs, and add a way to do cross-content linking.
This commit is contained in:
parent
f653118658
commit
c74abe579b
12 changed files with 228 additions and 125 deletions
|
|
@ -5,6 +5,7 @@ import random
|
|||
import logging
|
||||
import datetime
|
||||
import subprocess
|
||||
import shutil
|
||||
|
||||
from codecs import open
|
||||
from collections import defaultdict
|
||||
|
|
@ -15,9 +16,10 @@ from operator import attrgetter, itemgetter
|
|||
from jinja2 import (Environment, FileSystemLoader, PrefixLoader, ChoiceLoader,
|
||||
BaseLoader, TemplateNotFound)
|
||||
|
||||
from pelican.contents import Article, Page, Category, is_valid_content
|
||||
from pelican.contents import Article, Page, Category, StaticContent, \
|
||||
is_valid_content
|
||||
from pelican.readers import read_file
|
||||
from pelican.utils import copy, process_translations
|
||||
from pelican.utils import copy, process_translations, mkdir_p
|
||||
from pelican import signals
|
||||
|
||||
|
||||
|
|
@ -61,6 +63,7 @@ class Generator(object):
|
|||
# get custom Jinja filters from user settings
|
||||
custom_filters = self.settings.get('JINJA_FILTERS', {})
|
||||
self.env.filters.update(custom_filters)
|
||||
self.context['filenames'] = kwargs.get('filenames', {})
|
||||
|
||||
signals.generator_init.send(self)
|
||||
|
||||
|
|
@ -82,8 +85,10 @@ class Generator(object):
|
|||
|
||||
:param path: the path to search the file on
|
||||
:param exclude: the list of path to exclude
|
||||
:param extensions: the list of allowed extensions (if False, all
|
||||
extensions are allowed)
|
||||
"""
|
||||
if not extensions:
|
||||
if extensions is None:
|
||||
extensions = self.markup
|
||||
|
||||
files = []
|
||||
|
|
@ -97,10 +102,17 @@ class Generator(object):
|
|||
for e in exclude:
|
||||
if e in dirs:
|
||||
dirs.remove(e)
|
||||
files.extend([os.sep.join((root, f)) for f in temp_files
|
||||
if True in [f.endswith(ext) for ext in extensions]])
|
||||
for f in temp_files:
|
||||
if extensions is False or \
|
||||
(True in [f.endswith(ext) for ext in extensions]):
|
||||
files.append(os.sep.join((root, f)))
|
||||
return files
|
||||
|
||||
def add_filename(self, content):
|
||||
location = os.path.relpath(os.path.abspath(content.filename),
|
||||
os.path.abspath(self.path))
|
||||
self.context['filenames'][location] = content
|
||||
|
||||
def _update_context(self, items):
|
||||
"""Update the context with the given items from the currrent
|
||||
processor.
|
||||
|
|
@ -300,7 +312,7 @@ class ArticlesGenerator(Generator):
|
|||
self.generate_drafts(write)
|
||||
|
||||
def generate_context(self):
|
||||
"""change the context"""
|
||||
"""Add the articles into the shared context"""
|
||||
|
||||
article_path = os.path.normpath( # we have to remove trailing slashes
|
||||
os.path.join(self.path, self.settings['ARTICLE_DIR'])
|
||||
|
|
@ -341,10 +353,12 @@ class ArticlesGenerator(Generator):
|
|||
|
||||
signals.article_generate_context.send(self, metadata=metadata)
|
||||
article = Article(content, metadata, settings=self.settings,
|
||||
filename=f)
|
||||
filename=f, context=self.context)
|
||||
if not is_valid_content(article, f):
|
||||
continue
|
||||
|
||||
self.add_filename(article)
|
||||
|
||||
if article.status == "published":
|
||||
if hasattr(article, 'tags'):
|
||||
for tag in article.tags:
|
||||
|
|
@ -440,11 +454,14 @@ class PagesGenerator(Generator):
|
|||
except Exception, e:
|
||||
logger.warning(u'Could not process %s\n%s' % (f, str(e)))
|
||||
continue
|
||||
signals.pages_generate_context.send(self, metadata=metadata )
|
||||
signals.pages_generate_context.send(self, metadata=metadata)
|
||||
page = Page(content, metadata, settings=self.settings,
|
||||
filename=f)
|
||||
filename=f, context=self.context)
|
||||
if not is_valid_content(page, f):
|
||||
continue
|
||||
|
||||
self.add_filename(page)
|
||||
|
||||
if page.status == "published":
|
||||
all_pages.append(page)
|
||||
elif page.status == "hidden":
|
||||
|
|
@ -479,17 +496,33 @@ class StaticGenerator(Generator):
|
|||
copy(path, source, os.path.join(output_path, destination),
|
||||
final_path, overwrite=True)
|
||||
|
||||
def generate_output(self, writer):
|
||||
def generate_context(self):
|
||||
self.staticfiles = []
|
||||
|
||||
self._copy_paths(self.settings['STATIC_PATHS'], self.path,
|
||||
'static', self.output_path)
|
||||
# walk static paths
|
||||
for static_path in self.settings['STATIC_PATHS']:
|
||||
for f in self.get_files(
|
||||
os.path.join(self.path, static_path), extensions=False):
|
||||
f_rel = os.path.relpath(f, self.path)
|
||||
# TODO remove this hardcoded 'static' subdirectory
|
||||
sc = StaticContent(f_rel, os.path.join('static', f_rel),
|
||||
settings=self.settings)
|
||||
self.staticfiles.append(sc)
|
||||
self.context['filenames'][f_rel] = sc
|
||||
# same thing for FILES_TO_COPY
|
||||
for src, dest in self.settings['FILES_TO_COPY']:
|
||||
sc = StaticContent(src, dest, settings=self.settings)
|
||||
self.staticfiles.append(sc)
|
||||
self.context['filenames'][src] = sc
|
||||
|
||||
def generate_output(self, writer):
|
||||
self._copy_paths(self.settings['THEME_STATIC_PATHS'], self.theme,
|
||||
'theme', self.output_path, '.')
|
||||
|
||||
# copy all the files needed
|
||||
for source, destination in self.settings['FILES_TO_COPY']:
|
||||
copy(source, self.path, self.output_path, destination,
|
||||
overwrite=True)
|
||||
# copy all StaticContent files
|
||||
for sc in self.staticfiles:
|
||||
mkdir_p(os.path.dirname(sc.save_as))
|
||||
shutil.copy(sc.filepath, sc.save_as)
|
||||
logger.info('copying %s to %s' % (sc.filepath, sc.save_as))
|
||||
|
||||
|
||||
class PdfGenerator(Generator):
|
||||
|
|
@ -532,8 +565,8 @@ class PdfGenerator(Generator):
|
|||
try:
|
||||
os.mkdir(pdf_path)
|
||||
except OSError:
|
||||
logger.error("Couldn't create the pdf output folder in " + pdf_path)
|
||||
pass
|
||||
logger.error("Couldn't create the pdf output folder in " +
|
||||
pdf_path)
|
||||
|
||||
for article in self.context['articles']:
|
||||
self._create_pdf(article, pdf_path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue