def test_metadata_url_format(self): # Arbitrary metadata should be passed through url_format() page = Page(**self.page_kwargs) self.assertIn('summary', page.url_format.keys()) page.metadata['directory'] = 'test-dir' page.settings = get_settings(PAGE_SAVE_AS='{directory}/{slug}') self.assertEqual(page.save_as, 'test-dir/foo-bar')
def test_get_content(self): # Test that the content is updated with the relative links to # filenames, tags and categories. settings = get_settings() args = self.page_kwargs.copy() args['settings'] = settings # Tag args['content'] = ('A simple test, with a ' '<a href="|tag|tagname">link</a>') page = Page(**args) content = page.get_content('http://notmyidea.org') self.assertEqual( content, ('A simple test, with a ' '<a href="http://notmyidea.org/tag/tagname.html">link</a>')) # Category args['content'] = ('A simple test, with a ' '<a href="|category|category">link</a>') page = Page(**args) content = page.get_content('http://notmyidea.org') self.assertEqual( content, ('A simple test, with a ' '<a href="http://notmyidea.org/category/category.html">link</a>'))
def test_metadata_url_format(self): # Arbitrary metadata should be passed through url_format() page = Page(**self.page_kwargs) self.assertIn("summary", page.url_format.keys()) page.metadata["directory"] = "test-dir" page.settings = get_settings(PAGE_SAVE_AS="{directory}/{slug}") self.assertEqual(page.save_as, "test-dir/foo-bar")
def test_save_as(self): # if a lang is not the default lang, save_as should be set accordingly page = Page('content', {'title': 'foobar', 'lang': 'fr'}) #default lang is en self.assertEqual(page.save_as, "foobar-fr.html") # otherwise, if a title is defined, save_as should be set page = Page('content', {'title': 'foobar'}) page.save_as = 'foobar.html'
def test_metadata_url_format(self): """Arbitrary metadata should be passed through url_format() """ page = Page(**self.page_kwargs) self.assertIn('summary', page.url_format.keys()) page.metadata['directory'] = 'test-dir' page.settings = _DEFAULT_CONFIG.copy() page.settings['PAGE_SAVE_AS'] = '{directory}/{slug}' self.assertEqual(page.save_as, 'test-dir/foo-bar')
def test_metadata_url_format(self): """Arbitrary metadata should be passed through url_format() """ page = Page(**self.page_kwargs) self.assertIn("summary", page.url_format.keys()) page.metadata["directory"] = "test-dir" page.settings = _DEFAULT_CONFIG.copy() page.settings["PAGE_SAVE_AS"] = "{directory}/{slug}" self.assertEqual(page.save_as, "test-dir/foo-bar")
def test_mandatory_properties(self): # If the title is not set, must throw an exception. page = Page('content') self.assertFalse(page._has_valid_mandatory_properties()) self.assertLogCountEqual( count=1, msg="Skipping .*: could not find information about 'title'", level=logging.ERROR) page = Page('content', metadata={'title': 'foobar'}) self.assertTrue(page._has_valid_mandatory_properties())
def test_summary_get_summary_warning(self): """calling ._get_summary() should issue a warning""" page_kwargs = self._copy_page_kwargs() page = Page(**page_kwargs) self.assertEqual(page.summary, TEST_SUMMARY) self.assertEqual(page._get_summary(), TEST_SUMMARY) self.assertLogCountEqual( count=1, msg="_get_summary\(\) has been deprecated since 3\.6\.4\. " "Use the summary decorator instead", level=logging.WARNING)
def test_category_link_syntax(self): "{category} link syntax triggers url replacement." html = '<a href="{category}foo">link</a>' page = Page(content=html, metadata={'title': 'fakepage'}, settings=self.settings, source_path=os.path.join('dir', 'otherdir', 'fakepage.md'), context=self.context) content = page.get_content('') self.assertNotEqual(content, html)
def test_save_as(self): # if a lang is not the default lang, save_as should be set accordingly page = Page("content", {"title": "foobar", "lang": "fr"}) # default lang is en self.assertEqual(page.save_as, "foobar-fr.html") # otherwise, if a title is defined, save_as should be set page = Page("content", {"title": "foobar"}) page.save_as = "foobar.html" # if no title is given, there is no save_as page = Page("content") self.assertFalse(hasattr(page, "save_as"))
def test_save_as(self): """If a lang is not the default lang, save_as should be set accordingly. """ # if a title is defined, save_as should be set page = Page(**self.page_kwargs) page.save_as = 'foo-bar.html' # if a language is defined, save_as should include it accordingly self.page_kwargs['metadata'].update({'lang': 'fr', }) page = Page(**self.page_kwargs) self.assertEqual(page.save_as, "foo-bar-fr.html")
def test_link_to_unknown_file(self): "{filename} link to unknown file should trigger warning." html = '<a href="{filename}foo">link</a>' page = Page(content=html, metadata={'title': 'fakepage'}, settings=self.settings, source_path=os.path.join('dir', 'otherdir', 'fakepage.md'), context=self.context) content = page.get_content('') self.assertEqual(content, html) self.assertLogCountEqual( count=1, msg="Unable to find 'foo', skipping url replacement.", level=logging.WARNING)
def test_unknown_link_syntax(self): "{unknown} link syntax should trigger warning." html = '<a href="{unknown}foo">link</a>' page = Page(content=html, metadata={'title': 'fakepage'}, settings=self.settings, source_path=os.path.join('dir', 'otherdir', 'fakepage.md'), context=self.context) content = page.get_content('') self.assertEqual(content, html) self.assertLogCountEqual( count=1, msg="Replacement Indicator 'unknown' not recognized, " "skipping replacement", level=logging.WARNING)
def test_attach_link_syntax(self): """{attach} link syntax triggers output path override & url replacement. """ html = '<a href="{attach}../foo.jpg">link</a>' page = Page(content=html, metadata={'title': 'fakepage'}, settings=self.settings, source_path=os.path.join('dir', 'otherdir', 'fakepage.md'), context=self.context) content = page.get_content('') self.assertNotEqual(content, html, "{attach} link syntax did not trigger URL replacement.") expected_save_as = os.path.join('outpages', 'foo.jpg') self.assertEqual(self.static.save_as, expected_save_as) self.assertEqual(self.static.url, path_to_url(expected_save_as))
def test_index_link_syntax(self): "{index} link syntax triggers url replacement." html = '<a href="{index}">link</a>' page = Page( content=html, metadata={'title': 'fakepage'}, settings=self.settings, source_path=os.path.join('dir', 'otherdir', 'fakepage.md'), context=self.context) content = page.get_content('') self.assertNotEqual(content, html) expected_html = ('<a href="' + '/'.join((self.settings['SITEURL'], self.settings['INDEX_SAVE_AS'])) + '">link</a>') self.assertEqual(content, expected_html)
def test_mandatory_properties(self): # if the title is not set, must throw an exception page = Page('content', {'title':'foobar'}) page.mandatory_properties = ('title', 'foo') with self.assertRaises(NameError) as cm: page.check_properties() page = Page('content', metadata={'title': 'foobar'}) page.check_properties()
def generate_context(self): all_pages = [] for f in self.get_files(os.sep.join((self.path, 'pages'))): content, metadata = read_file(f) page = Page(content, metadata, settings=self.settings, filename=f) if not is_valid_content(page, f): continue if self.settings.get('CLEAN_URLS_NO_PROXY'): # cleaning page url page.save_as = os.path.join(page.slug, 'index.html') page.url = os.path.dirname(page.save_as) + '/' all_pages.append(page) self.pages, self.translations = process_translations(all_pages) self._update_context(('pages', )) self.context['PAGES'] = self.pages
def test_mandatory_properties(self): # if the title is not set, must throw an exception page = Page("content") with self.assertRaises(NameError) as cm: page.check_properties() page = Page("content", metadata={"title": "foobar"}) page.check_properties()
def test_attach_to_does_not_override_an_override(self): """attach_to() does not override paths that were overridden elsewhere. (For example, by the user with EXTRA_PATH_METADATA) """ customstatic = Static(content=None, metadata=dict(save_as='customfoo.jpg', url='customfoo.jpg'), settings=self.settings, source_path=os.path.join('dir', 'foo.jpg'), context=self.settings.copy()) page = Page(content="fake page", metadata={'title': 'fakepage'}, settings=self.settings, source_path=os.path.join('dir', 'fakepage.md')) customstatic.attach_to(page) self.assertEqual(customstatic.save_as, 'customfoo.jpg') self.assertEqual(customstatic.url, 'customfoo.jpg')
def test_intrasite_link_markdown_spaces(self): cls_name = '_DummyArticle' article = type(cls_name, (object,), {'url': 'article-spaces.html'}) args = self.page_kwargs.copy() args['settings'] = get_settings() args['source_path'] = 'content' args['context']['generated_content'] = {'article spaces.rst': article} # An intrasite link via filename with %20 as a space args['content'] = ( 'A simple test, with a ' '<a href="|filename|article%20spaces.rst">link</a>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a ' '<a href="http://notmyidea.org/article-spaces.html">link</a>' )
def test_intrasite_link_to_static_content_with_filename(self): """Test linking to a static resource with deprecated {filename} """ cls_name = '_DummyAsset' args = self.page_kwargs.copy() args['settings'] = get_settings() args['source_path'] = 'content' args['context']['static_content'] = { 'poster.jpg': type(cls_name, (object,), {'url': 'images/poster.jpg'})} args['content'] = ( 'A simple test, with a link to a' '<a href="{filename}poster.jpg">poster</a>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a link to a' '<a href="http://notmyidea.org/images/poster.jpg">poster</a>' )
def test_intrasite_link_markdown_spaces(self): # Markdown introduces %20 instead of spaces, this tests that # we support markdown doing this. cls_name = '_DummyArticle' if six.PY3 else b'_DummyArticle' article = type(cls_name, (object,), {'url': 'article-spaces.html'}) args = self.page_kwargs.copy() args['settings'] = get_settings() args['source_path'] = 'content' args['context']['filenames'] = {'article spaces.rst': article} # An intrasite link via filename with %20 as a space args['content'] = ( 'A simple test, with a ' '<a href="|filename|article%20spaces.rst">link</a>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a ' '<a href="http://notmyidea.org/article-spaces.html">link</a>' )
def generate_context(self): all_pages = [] hidden_pages = [] for f in self.get_files(os.path.join(self.path, self.settings['PAGE_DIR']), exclude=self.settings['PAGE_EXCLUDES']): try: content, metadata = read_file(f, settings=self.settings) except Exception as e: logger.warning('Could not process %s\n%s' % (f, str(e))) continue signals.pages_generate_context.send(self, metadata=metadata) page = Page(content, metadata, settings=self.settings, source_path=f, context=self.context) if not is_valid_content(page, f): continue self.add_source_path(page) if page.status == "published": all_pages.append(page) elif page.status == "hidden": hidden_pages.append(page) else: logger.warning("Unknown status %s for file %s, skipping it." % (repr(page.status), repr(f))) self.pages, self.translations = process_translations(all_pages) self.hidden_pages, self.hidden_translations = ( process_translations(hidden_pages)) self._update_context(('pages', )) self.context['PAGES'] = self.pages signals.pages_generator_finalized.send(self)
def generate_context(self): all_pages = [] hidden_pages = [] for f in self.get_files(os.path.join(self.path, self.settings['PAGE_DIR']), exclude=self.settings['PAGE_EXCLUDES']): try: content, metadata = read_file(f, settings=self.settings) except Exception, e: logger.warning(u'Could not process %s\n%s' % (f, str(e))) continue signals.pages_generate_context.send(self, metadata=metadata) page = Page(content, metadata, settings=self.settings, filename=f) if not is_valid_content(page, f): continue if page.status == "published": all_pages.append(page) elif page.status == "hidden": hidden_pages.append(page) else: logger.warning( u"Unknown status %s for file %s, skipping it." % (repr(unicode.encode(page.status, 'utf-8')), repr(f)))
def gen_page_and_html_from_rst(self, rstPath): content, metadata = self.reader.read(rstPath) page = Page(content=content, metadata=metadata) context = self.settings.copy() context['generated_content'] = {} context['static_links'] = set() context['static_content'] = {} context['localsiteurl'] = self.settings['SITEURL'] generator = PagesGenerator(context=context, settings=self.settings, path=CONTENT_DIR, theme=self.settings['THEME'], output_path=OUTPUT_DIR) generator.generate_context() f = lambda a: True if (a.slug == page.slug) else False result = list(filter(f, generator.context["pages"]))[0] self.writer.write_file(result.save_as, generator.get_template('page'), generator.context, page=result) soup = BeautifulSoup( open("./" + self.writer.output_path + '/' + result.save_as), "html.parser") return (result, soup)
def test_intrasite_link_source_and_generated(self): """Test linking both to the source and the generated article """ cls_name = '_DummyAsset' args = self.page_kwargs.copy() args['settings'] = get_settings() args['source_path'] = 'content' args['context']['generated_content'] = { 'article.rst': type(cls_name, (object, ), {'url': 'article.html'}) } args['context']['static_content'] = { 'article.rst': type(cls_name, (object, ), {'url': 'article.rst'}) } args['content'] = ( 'A simple test, with a link to an' '<a href="{filename}article.rst">article</a> and its' '<a href="{static}article.rst">source</a>') content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a link to an' '<a href="http://notmyidea.org/article.html">article</a> and its' '<a href="http://notmyidea.org/article.rst">source</a>')
def test_get_content(self): # Test that the content is updated with the relative links to # filenames, tags and categories. settings = get_settings() args = self.page_kwargs.copy() args['settings'] = settings # Tag args['content'] = ('A simple test, with a ' '<a href="|tag|tagname">link</a>') page = Page(**args) content = page.get_content('http://notmyidea.org') self.assertEqual(content, ('A simple test, with a ' '<a href="tag/tagname.html">link</a>')) # Category args['content'] = ('A simple test, with a ' '<a href="|category|category">link</a>') page = Page(**args) content = page.get_content('http://notmyidea.org') self.assertEqual(content, ('A simple test, with a ' '<a href="category/category.html">link</a>'))
def test_slug(self): """If a title is given, it should be used to generate the slug.""" page = Page(**self.page_kwargs) self.assertEqual(page.slug, 'foo-bar')
def test_summary_from_metadata(self): # If a :summary: metadata is given, it should be used page = Page(**self.page_kwargs) self.assertEqual(page.summary, TEST_SUMMARY)
def test_mandatory_properties(self): """If the title is not set, must throw an exception.""" self.assertRaises(AttributeError, Page, 'content') page = Page(**self.page_kwargs) page.check_properties()
def test_intrasite_link(self): # type does not take unicode in PY2 and bytes in PY3, which in # combination with unicode literals leads to following insane line: cls_name = '_DummyArticle' if six.PY3 else b'_DummyArticle' article = type(cls_name, (object,), {'url': 'article.html'}) args = self.page_kwargs.copy() args['settings'] = get_settings() args['source_path'] = 'content' args['context']['generated_content'] = {'article.rst': article} # Classic intrasite link via filename args['content'] = ( 'A simple test, with a ' '<a href="|filename|article.rst">link</a>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a ' '<a href="http://notmyidea.org/article.html">link</a>' ) # fragment args['content'] = ( 'A simple test, with a ' '<a href="|filename|article.rst#section-2">link</a>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a ' '<a href="http://notmyidea.org/article.html#section-2">link</a>' ) # query args['content'] = ( 'A simple test, with a ' '<a href="|filename|article.rst' '?utm_whatever=234&highlight=word">link</a>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a ' '<a href="http://notmyidea.org/article.html' '?utm_whatever=234&highlight=word">link</a>' ) # combination args['content'] = ( 'A simple test, with a ' '<a href="|filename|article.rst' '?utm_whatever=234&highlight=word#section-2">link</a>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a ' '<a href="http://notmyidea.org/article.html' '?utm_whatever=234&highlight=word#section-2">link</a>' ) # also test for summary in metadata parsed = ( 'A simple summary test, with a ' '<a href="|filename|article.rst">link</a>' ) linked = ( 'A simple summary test, with a ' '<a href="http://notmyidea.org/article.html">link</a>' ) args['settings']['FORMATTED_FIELDS'] = ['summary', 'custom'] args['metadata']['summary'] = parsed args['metadata']['custom'] = parsed args['context']['localsiteurl'] = 'http://notmyidea.org' p = Page(**args) # This is called implicitly from all generators and Pelican.run() once # all files are processed. Here we process just one page so it needs # to be called explicitly. p.refresh_metadata_intersite_links() self.assertEqual(p.summary, linked) self.assertEqual(p.custom, linked)
def test_intrasite_link_more(self): # type does not take unicode in PY2 and bytes in PY3, which in # combination with unicode literals leads to following insane line: cls_name = '_DummyAsset' if six.PY3 else b'_DummyAsset' args = self.page_kwargs.copy() args['settings'] = get_settings() args['source_path'] = 'content' args['context']['filenames'] = { 'images/poster.jpg': type( cls_name, (object,), {'url': 'images/poster.jpg'}), 'assets/video.mp4': type( cls_name, (object,), {'url': 'assets/video.mp4'}), 'images/graph.svg': type( cls_name, (object,), {'url': 'images/graph.svg'}), 'reference.rst': type( cls_name, (object,), {'url': 'reference.html'}), } # video.poster args['content'] = ( 'There is a video with poster ' '<video controls poster="{filename}/images/poster.jpg">' '<source src="|filename|/assets/video.mp4" type="video/mp4">' '</video>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'There is a video with poster ' '<video controls poster="http://notmyidea.org/images/poster.jpg">' '<source src="http://notmyidea.org/assets/video.mp4"' ' type="video/mp4">' '</video>' ) # object.data args['content'] = ( 'There is a svg object ' '<object data="{filename}/images/graph.svg"' ' type="image/svg+xml">' '</object>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'There is a svg object ' '<object data="http://notmyidea.org/images/graph.svg"' ' type="image/svg+xml">' '</object>' ) # blockquote.cite args['content'] = ( 'There is a blockquote with cite attribute ' '<blockquote cite="{filename}reference.rst">blah blah</blockquote>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'There is a blockquote with cite attribute ' '<blockquote cite="http://notmyidea.org/reference.html">' 'blah blah' '</blockquote>' )
def test_intrasite_link(self): # type does not take unicode in PY2 and bytes in PY3, which in # combination with unicode literals leads to following insane line: cls_name = '_DummyArticle' if six.PY3 else b'_DummyArticle' article = type(cls_name, (object,), {'url': 'article.html'}) args = self.page_kwargs.copy() args['settings'] = get_settings() args['source_path'] = 'content' args['context']['filenames'] = {'article.rst': article} # Classic intrasite link via filename args['content'] = ( 'A simple test, with a ' '<a href="|filename|article.rst">link</a>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a ' '<a href="http://notmyidea.org/article.html">link</a>' ) # fragment args['content'] = ( 'A simple test, with a ' '<a href="|filename|article.rst#section-2">link</a>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a ' '<a href="http://notmyidea.org/article.html#section-2">link</a>' ) # query args['content'] = ( 'A simple test, with a ' '<a href="|filename|article.rst' '?utm_whatever=234&highlight=word">link</a>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a ' '<a href="http://notmyidea.org/article.html' '?utm_whatever=234&highlight=word">link</a>' ) # combination args['content'] = ( 'A simple test, with a ' '<a href="|filename|article.rst' '?utm_whatever=234&highlight=word#section-2">link</a>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a ' '<a href="http://notmyidea.org/article.html' '?utm_whatever=234&highlight=word#section-2">link</a>' ) # also test for summary in metadata args['metadata']['summary'] = ( 'A simple summary test, with a ' '<a href="|filename|article.rst">link</a>' ) args['context']['localsiteurl'] = 'http://notmyidea.org' p = Page(**args) self.assertEqual( p.summary, 'A simple summary test, with a ' '<a href="http://notmyidea.org/article.html">link</a>' )
def test_slug(self): # if a title is given, it should be used to generate the slug page = Page('content', {'title': 'foobar is foo'}) self.assertEqual(page.slug, 'foobar-is-foo')
def test_props_must_exist(self): page = Page('content') self.assertFalse(page._has_valid_mandatory_properties()) new_page = Page('content', metadata={'title': 'Pelican'}) self.assertTrue(new_page._has_valid_mandatory_properties())
def test_intrasite_link_more(self): cls_name = '_DummyAsset' args = self.page_kwargs.copy() args['settings'] = get_settings() args['source_path'] = 'content' args['context']['static_content'] = { 'images/poster.jpg': type(cls_name, (object,), {'url': 'images/poster.jpg'}), 'assets/video.mp4': type(cls_name, (object,), {'url': 'assets/video.mp4'}), 'images/graph.svg': type(cls_name, (object,), {'url': 'images/graph.svg'}), } args['context']['generated_content'] = { 'reference.rst': type(cls_name, (object,), {'url': 'reference.html'}), } # video.poster args['content'] = ( 'There is a video with poster ' '<video controls poster="{static}/images/poster.jpg">' '<source src="|static|/assets/video.mp4" type="video/mp4">' '</video>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'There is a video with poster ' '<video controls poster="http://notmyidea.org/images/poster.jpg">' '<source src="http://notmyidea.org/assets/video.mp4"' ' type="video/mp4">' '</video>' ) # object.data args['content'] = ( 'There is a svg object ' '<object data="{static}/images/graph.svg"' ' type="image/svg+xml">' '</object>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'There is a svg object ' '<object data="http://notmyidea.org/images/graph.svg"' ' type="image/svg+xml">' '</object>' ) # blockquote.cite args['content'] = ( 'There is a blockquote with cite attribute ' '<blockquote cite="{filename}reference.rst">blah blah</blockquote>' ) content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'There is a blockquote with cite attribute ' '<blockquote cite="http://notmyidea.org/reference.html">' 'blah blah' '</blockquote>' )
def test_intrasite_link(self): cls_name = '_DummyArticle' article = type(cls_name, (object, ), {'url': 'article.html'}) args = self.page_kwargs.copy() args['settings'] = get_settings() args['source_path'] = 'content' args['context']['generated_content'] = {'article.rst': article} # Classic intrasite link via filename args['content'] = ('A simple test, with a ' '<a href="|filename|article.rst">link</a>') content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a ' '<a href="http://notmyidea.org/article.html">link</a>') # fragment args['content'] = ( 'A simple test, with a ' '<a href="|filename|article.rst#section-2">link</a>') content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a ' '<a href="http://notmyidea.org/article.html#section-2">link</a>') # query args['content'] = ('A simple test, with a ' '<a href="|filename|article.rst' '?utm_whatever=234&highlight=word">link</a>') content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a ' '<a href="http://notmyidea.org/article.html' '?utm_whatever=234&highlight=word">link</a>') # combination args['content'] = ( 'A simple test, with a ' '<a href="|filename|article.rst' '?utm_whatever=234&highlight=word#section-2">link</a>') content = Page(**args).get_content('http://notmyidea.org') self.assertEqual( content, 'A simple test, with a ' '<a href="http://notmyidea.org/article.html' '?utm_whatever=234&highlight=word#section-2">link</a>') # also test for summary in metadata parsed = ('A simple summary test, with a ' '<a href="|filename|article.rst">link</a>') linked = ('A simple summary test, with a ' '<a href="http://notmyidea.org/article.html">link</a>') args['settings']['FORMATTED_FIELDS'] = ['summary', 'custom'] args['metadata']['summary'] = parsed args['metadata']['custom'] = parsed args['context']['localsiteurl'] = 'http://notmyidea.org' p = Page(**args) # This is called implicitly from all generators and Pelican.run() once # all files are processed. Here we process just one page so it needs # to be called explicitly. p.refresh_metadata_intersite_links() self.assertEqual(p.summary, linked) self.assertEqual(p.custom, linked)
def __init__(self, content, metadata=None, settings=None, source_path=None, context=None): self._amp_content = getattr(content, 'amp_data', None) Page.__init__(self, content, metadata=metadata, settings=settings, source_path=source_path, context=context)