mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
new HTMLReader
This commit is contained in:
parent
d93530a6ea
commit
cc1988fbda
5 changed files with 146 additions and 97 deletions
6
tests/content/article_with_keywords.html
Normal file
6
tests/content/article_with_keywords.html
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>This is a super article !</title>
|
||||
<meta name="keywords" contents="foo, bar, foobar" />
|
||||
</head>
|
||||
</html>
|
||||
15
tests/content/article_with_metadata.html
Normal file
15
tests/content/article_with_metadata.html
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>This is a super article !</title>
|
||||
<meta name="tags" contents="foo, bar, foobar" />
|
||||
<meta name="date" contents="2010-12-02 10:14" />
|
||||
<meta name="category" contents="yeah" />
|
||||
<meta name="author" contents="Alexis Métaireau" />
|
||||
<meta name="custom_field" contents="http://notmyidea.org" />
|
||||
</head>
|
||||
<body>
|
||||
Multi-line metadata should be supported
|
||||
as well as <strong>inline markup</strong>.
|
||||
<!-- PELICAN_END_SUMMARY -->
|
||||
</body>
|
||||
</html>
|
||||
6
tests/content/article_with_uppercase_metadata.html
Normal file
6
tests/content/article_with_uppercase_metadata.html
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>This is a super article !</title>
|
||||
<meta name="Category" contents="Yeah" />
|
||||
</head>
|
||||
</html>
|
||||
|
|
@ -86,3 +86,41 @@ class MdReaderTest(unittest.TestCase):
|
|||
"<p>This is another markdown test file. Uses the mkd extension.</p>"
|
||||
|
||||
self.assertEqual(content, expected)
|
||||
|
||||
class HTMLReaderTest(unittest.TestCase):
|
||||
|
||||
def test_article_with_metadata(self):
|
||||
reader = readers.HTMLReader({})
|
||||
content, metadata = reader.read(_filename('article_with_metadata.html'))
|
||||
expected = {
|
||||
'category': 'yeah',
|
||||
'author': u'Alexis Métaireau',
|
||||
'title': 'This is a super article !',
|
||||
'summary': u'''
|
||||
Multi-line metadata should be supported
|
||||
as well as <strong>inline markup</strong>.
|
||||
''',
|
||||
'date': datetime.datetime(2010, 12, 2, 10, 14),
|
||||
'tags': ['foo', 'bar', 'foobar'],
|
||||
'custom_field': 'http://notmyidea.org',
|
||||
}
|
||||
|
||||
for key, value in expected.items():
|
||||
self.assertEquals(value, metadata[key], key)
|
||||
|
||||
def test_article_with_keywords(self):
|
||||
reader = readers.HTMLReader({})
|
||||
content, metadata = reader.read(_filename('article_with_keywords.html'))
|
||||
expected = {
|
||||
'tags': ['foo', 'bar', 'foobar'],
|
||||
}
|
||||
|
||||
for key, value in expected.items():
|
||||
self.assertEquals(value, metadata[key], key)
|
||||
|
||||
def test_article_metadata_key_lowercase(self):
|
||||
"""Keys of metadata should be lowercase."""
|
||||
reader = readers.HTMLReader({})
|
||||
content, metadata = reader.read(_filename('article_with_uppercase_metadata.html'))
|
||||
self.assertIn('category', metadata, "Key should be lowercase.")
|
||||
self.assertEquals('Yeah', metadata.get('category'), "Value keeps cases.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue