Skip to content

Commit 87270c8

Browse files
committed
Revert "Introduce INTERNAL_LINK_FIELDS setting."
This reverts commit 8343912.
1 parent 8343912 commit 87270c8

File tree

4 files changed

+61
-89
lines changed

4 files changed

+61
-89
lines changed

docs/changelog.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ Next release
55
============
66

77
* New signal: ``feed_generated``
8-
* Introduced ``INTERNAL_LINK_FIELDS`` to allow URL replacement in user-defined
9-
metadata fields.
108

119
3.7.1 (2017-01-10)
1210
==================

docs/settings.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,6 @@ Basic settings
312312
A list of metadata fields containing reST/Markdown content to be parsed and
313313
translated to HTML.
314314

315-
.. data:: INTERNAL_LINK_FIELDS = []
316-
317-
A list of metadata fields containing links to internal content to be
318-
converted to absolute URLs. For example, a theme can use a ``:cover:``
319-
article metadata field to include an image on page background or in a social
320-
meta tag. For details see :ref:`ref-linking-to-internal-content`.
321315

322316
URL settings
323317
============

pelican/contents.py

Lines changed: 61 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -204,68 +204,6 @@ def get_url_setting(self, key):
204204
key = key if self.in_default_lang else 'lang_%s' % key
205205
return self._expand_settings(key)
206206

207-
def _link_replacer(self, siteurl, m):
208-
what = m.group('what')
209-
value = urlparse(m.group('value'))
210-
path = value.path
211-
origin = m.group('path')
212-
213-
# XXX Put this in a different location.
214-
if what in {'filename', 'attach'}:
215-
if path.startswith('/'):
216-
path = path[1:]
217-
else:
218-
# relative to the source path of this content
219-
path = self.get_relative_source_path(
220-
os.path.join(self.relative_dir, path)
221-
)
222-
223-
if path not in self._context['filenames']:
224-
unquoted_path = path.replace('%20', ' ')
225-
226-
if unquoted_path in self._context['filenames']:
227-
path = unquoted_path
228-
229-
linked_content = self._context['filenames'].get(path)
230-
if linked_content:
231-
if what == 'attach':
232-
if isinstance(linked_content, Static):
233-
linked_content.attach_to(self)
234-
else:
235-
logger.warning(
236-
"%s used {attach} link syntax on a "
237-
"non-static file. Use {filename} instead.",
238-
self.get_relative_source_path())
239-
origin = '/'.join((siteurl, linked_content.url))
240-
origin = origin.replace('\\', '/') # for Windows paths.
241-
else:
242-
logger.warning(
243-
"Unable to find '%s', skipping url replacement.",
244-
value.geturl(), extra={
245-
'limit_msg': ("Other resources were not found "
246-
"and their urls not replaced")})
247-
elif what == 'category':
248-
origin = '/'.join((siteurl, Category(path, self.settings).url))
249-
elif what == 'tag':
250-
origin = '/'.join((siteurl, Tag(path, self.settings).url))
251-
elif what == 'index':
252-
origin = '/'.join((siteurl, self.settings['INDEX_SAVE_AS']))
253-
elif what == 'author':
254-
origin = '/'.join((siteurl, Author(path, self.settings).url))
255-
else:
256-
logger.warning(
257-
"Replacement Indicator '%s' not recognized, "
258-
"skipping replacement",
259-
what)
260-
261-
# keep all other parts, such as query, fragment, etc.
262-
parts = list(value)
263-
parts[2] = origin
264-
origin = urlunparse(parts)
265-
266-
return ''.join((m.group('markup'), m.group('quote'), origin,
267-
m.group('quote')))
268-
269207
def _update_content(self, content, siteurl):
270208
"""Update the content attribute.
271209
@@ -289,26 +227,69 @@ def _update_content(self, content, siteurl):
289227
\2""".format(instrasite_link_regex)
290228
hrefs = re.compile(regex, re.X)
291229

292-
return hrefs.sub(lambda m: self._link_replacer(siteurl, m), content)
230+
def replacer(m):
231+
what = m.group('what')
232+
value = urlparse(m.group('value'))
233+
path = value.path
234+
origin = m.group('path')
293235

294-
def __getattribute__(self, name):
295-
try:
296-
# Avoid infinite recursion
297-
settings = object.__getattribute__(self, 'settings')
298-
link_fields = settings['INTERNAL_LINK_FIELDS']
299-
if name in link_fields:
300-
link_regex = r"""^
301-
(?P<markup>)(?P<quote>)
302-
(?P<path>{0}(?P<value>.*))
303-
$""".format(settings['INTRASITE_LINK_REGEX'])
304-
links = re.compile(link_regex, re.X)
305-
return links.sub(
306-
lambda m: self._link_replacer(self.get_siteurl(), m),
307-
object.__getattribute__(self, name))
236+
# XXX Put this in a different location.
237+
if what in {'filename', 'attach'}:
238+
if path.startswith('/'):
239+
path = path[1:]
240+
else:
241+
# relative to the source path of this content
242+
path = self.get_relative_source_path(
243+
os.path.join(self.relative_dir, path)
244+
)
245+
246+
if path not in self._context['filenames']:
247+
unquoted_path = path.replace('%20', ' ')
248+
249+
if unquoted_path in self._context['filenames']:
250+
path = unquoted_path
251+
252+
linked_content = self._context['filenames'].get(path)
253+
if linked_content:
254+
if what == 'attach':
255+
if isinstance(linked_content, Static):
256+
linked_content.attach_to(self)
257+
else:
258+
logger.warning(
259+
"%s used {attach} link syntax on a "
260+
"non-static file. Use {filename} instead.",
261+
self.get_relative_source_path())
262+
origin = '/'.join((siteurl, linked_content.url))
263+
origin = origin.replace('\\', '/') # for Windows paths.
264+
else:
265+
logger.warning(
266+
"Unable to find '%s', skipping url replacement.",
267+
value.geturl(), extra={
268+
'limit_msg': ("Other resources were not found "
269+
"and their urls not replaced")})
270+
elif what == 'category':
271+
origin = '/'.join((siteurl, Category(path, self.settings).url))
272+
elif what == 'tag':
273+
origin = '/'.join((siteurl, Tag(path, self.settings).url))
274+
elif what == 'index':
275+
origin = '/'.join((siteurl, self.settings['INDEX_SAVE_AS']))
276+
elif what == 'author':
277+
origin = '/'.join((siteurl, Author(path, self.settings).url))
308278
else:
309-
return object.__getattribute__(self, name)
310-
except AttributeError:
311-
return object.__getattribute__(self, name)
279+
logger.warning(
280+
"Replacement Indicator '%s' not recognized, "
281+
"skipping replacement",
282+
what)
283+
284+
# keep all other parts, such as query, fragment, etc.
285+
parts = list(value)
286+
parts[2] = origin
287+
origin = urlunparse(parts)
288+
289+
return ''.join((m.group('markup'), m.group('quote'), origin,
290+
m.group('quote')))
291+
292+
return hrefs.sub(replacer, content)
312293

313294
def get_siteurl(self):
314295
return self._context.get('localsiteurl', '')

pelican/settings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ def load_source(name, path):
145145
'LOAD_CONTENT_CACHE': False,
146146
'WRITE_SELECTED': [],
147147
'FORMATTED_FIELDS': ['summary'],
148-
'INTERNAL_LINK_FIELDS': [],
149148
}
150149

151150
PYGMENTS_RST_OPTIONS = None

0 commit comments

Comments
 (0)