getpelican / pelican

Static site generator that supports Markdown and reST syntax. Powered by Python.
https://getpelican.com
GNU Affero General Public License v3.0
12.51k stars 1.81k forks source link

Articles generated from asciidoc have wrong urls. #1324

Closed Jenselme closed 10 years ago

Jenselme commented 10 years ago

Hi,

I tried to wrote some articles using the Asciidoc markup but the generated are not named correctly. I let all the options by default, 'None' is added to the filename. By example, if :slug: toto the file is name toto-None.html.

Moreover, if I change the URL format:

ARTICLE_URL = 'posts/{date:%Y}/{date:%b}/{date:%d}/{slug}/'
ARTICLE_SAVE_AS = 'posts/{date:%Y}/{date:%b}/{date:%d}/{slug}/index.html'

The file still have the same URL. But if I use Markdown or Rest, everything is fine. An idea on what the problem might be?

Here is my article content, saved in posts/page3.asc:

Super Asciidoc
==============
Me <me@example.com>
:date: 2014-04-11
:tags: pelican, python
:category: python
:slug: toto
:summary: This is an article.

First article, just to test.

[source,python,src_numbered]
import re
# Coucou
if not None:

== To have ssh and scp
+yum install openssh-clients+

. To have bash completion: +yum install bash-completion+

. User and ssh
** useradd jenselme
** ssh-copy-id -i ~/.ssh/giskard.pub giskard
** usermod -L jenselme (usermod -U jenselme #to unlock)
** conf ssh

== To install owncloud in a nginx/pgsql
- add epel
- add remi
- enable both
- yum install postgresql postgresql-libs postgresql-server php-fpm php-gd php-ldap php-pear php-xml php-xmlrpc php-magickwand php-magpierss php-mbstring php-mcrypt php-shout php-snmp php-soap php-tidy php-pgsql php-pdo
- service postgresql initdb
- service postgresql start
- chkconfig postgresql on (ou update-rc.d nginx enable)
- su - -c "psql" postgres
- In postgres :
-- CREATE USER owncloud WITH PASSWORD 'pass';
-- CREATE DATABASE owncloud OWNER owncloud ENCODING 'UTF8';
kylef commented 10 years ago

Hi @Jenselme,

The meta-data keys need to be capitalised, so it's Slug instead of slug. See this example:

Test AsciiDoc File Header
=========================
:Author: Author O. Article
:Email: <author@nowhere.com>
:Date: 2011-09-15 09:05
:Category: Blog
:Tags: Linux, Python, Pelican

Used for pelican test
---------------------

The quick brown fox jumped over the lazy dog's back.
royemmerich commented 10 years ago

Seems I'm having the same issue. @kylef I tried your suggestion but my generated about page is called About-None.html. Any ideas?

ingwinlu commented 10 years ago

@royemmerich post full config and the page you want to parse which gets named About-None.html

royemmerich commented 10 years ago

Thanks @ingwinlu. Here is my pelicanconf.py

#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals

AUTHOR = u'Roy Martin Emmerich'
SITENAME = u'Infinite Fingers'
SITEURL = 'http://localhost:8000'

TIMEZONE = 'Europe/Berlin'
DEFAULT_LANG = u'en'
LOCALE = ('en_GB')
DATE_FORMATS = {
    'en': '%d %b %Y',
}

# Feed generation is usually not desired when developing
FEED_ALL_ATOM = None
CATEGORY_FEED_ATOM = None
TRANSLATION_FEED_ATOM = None

DELETE_OUTPUT_DIRECTORY = True

# Blogroll
LINKS = False

# Social widget
SOCIAL = (('LinkedIn', 'http://www.linkedin.com/in/royemmerich'),)

# Uncomment following line if you want document-relative URLs when developing
RELATIVE_URLS = True

THEME = 'themes/cait'

OUTPUT_PATH = 'output/'
PATH = 'content/'

ARTICLE_EXCLUDES = ('pages',)
ARTICLE_DIR = 'blog/'
ARTICLE_URL = 'blog/{slug}/'
ARTICLE_SAVE_AS = 'blog/{slug}/index.html'

PAGE_DIR = 'pages/'
PAGE_URL = '{slug}/'
PAGE_SAVE_AS = '{slug}/index.html'

PAGE_URL = '{slug}.html'
PAGE_SAVE_AS = '{slug}.html'

DIRECT_TEMPLATES = (('index', 'tags', 'categories', 'archives',))
DEFAULT_PAGINATION = 2
NEWEST_FIRST_ARCHIVES = False

PAGINATED_DIRECT_TEMPLATES = (('index', 'tags', 'categories', 'archives',))

and here is my About.asc file:

About
=====
:Author: Roy Martin Emmerich
:Email: <roy.emmerich@infinitefingers.com>
:Date: 2014-06-16 00:50
:Category: About
:Tags: About
:Slug: About

About Infinite Fingers
----------------------

image:../images/roy-300x348.jpg[]

What also doesn't seem to be working is saving the generated PAGES into {slug}/index.html. An output/pages folder is still being generated and the html pages are saved in there (e.g. About-None.html).

avaris commented 10 years ago

@royemmerich, you defined PAGE_URL and PAGE_SAVE_AS twice:

PAGE_URL = '{slug}/'
PAGE_SAVE_AS = '{slug}/index.html'

PAGE_URL = '{slug}.html'
PAGE_SAVE_AS = '{slug}.html'

So, the last one is active and you should get About.html, not About/index.html.

Regarding, output/pages/About-None.html: That looks like a translation that is formatted according to PAGE_LANG_URL and PAGE_LANG_SAVE_AS. Default for them is 'pages/{slug}-{lang}.html'. Check if you have more than one page with same slug (About in this case?). However, I don't know why you would get None for lang. It should default to DEFAULT_LANG.

royemmerich commented 10 years ago

@avaris thanks for spotting the duplication. I had just spent too much time experimenting with all the basic settings :smile: However it seems either way produces the same output namely: output/pages/About-None.html

I did notice, when running make html from my site's root directory, with a LOCALE setting of en_US that I was getting the following error:

WARNING: LOCALE option doesn't contain a correct value

So I used locale -a from the Linux command prompt to find all the available locales on my machine:

$ locale -a
...
en_US.utf8
de_DE.utf8
...

and changed it to a valid one (en_US.utf8). The results were the same. :frowning: I then ran locale from the Linux command prompt to see what my current settings are:

$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=de_DE.UTF-8
LC_TIME=de_DE.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=de_DE.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=de_DE.UTF-8
LC_NAME=de_DE.UTF-8
LC_ADDRESS=de_DE.UTF-8
LC_TELEPHONE=de_DE.UTF-8
LC_MEASUREMENT=de_DE.UTF-8
LC_IDENTIFICATION=de_DE.UTF-8
LC_ALL=

Notice that the values of some locale variables are enclosed in inverted commas ("). I also tried the following from within a python prompt:

>>> import os
>>> os.getenv('LANG')
'en_US.UTF-8'
>>> os.getenv('LC_CTYPE')
>>> os.getenv('LC_NUMERIC')
'de_DE.UTF-8'

Notice that only locale variables not surrounded in inverted commas produced a result within the python environment. So which one is valid from within the Pelican environment, en_US.utf8 or en_US.UTF-8?

I tried both options in my pelicanconf.py file:

DEFAULT_LANG = u'en_US.UTF-8'
LOCALE = ('en_US.UTF-8')
DATE_FORMATS = {
    'en_US.UTF-8': '%a %d %b %Y',
}

PAGE_URL = '{slug}.html'
PAGE_SAVE_AS = '{slug}.html'
PAGE_LANG_URL = '{slug}/'
PAGE_LANG_SAVE_AS = '{slug}/index.html'

and

DEFAULT_LANG = u'en_US.utf8'
LOCALE = ('en_US.utf8')
DATE_FORMATS = {
    'en_US.utf8': '%a %d %b %Y',
}

PAGE_URL = '{slug}.html'
PAGE_SAVE_AS = '{slug}.html'
PAGE_LANG_URL = '{slug}/'
PAGE_LANG_SAVE_AS = '{slug}/index.html'

Neither of these language options obey the PAGE_URL and PAGE_SAVE_AS settings listed above. Clearly python thinks my default language is not en_US.utf8 or en_US.UTF-8.

So at the moment my solution is just to make the PAGE_* and PAGE_LANG_* options the same.

Thanks for the super support! :thumbsup:

royemmerich commented 10 years ago

I played around a bit more and discovered if I change the LOCALE setting from en_US.utf8 to de_DE.utf8 then the day abbreviations change (e.g. Tue for US and Di for DE).

After checking out the DATE_FORMAT documentation I changed my pelicanconf.py file as follows:

LOCALE = ('en_US.utf8')
DATE_FORMATS = {
    'en_US.utf8': ('de_DE.utf8','%a %d %b %Y'),
}

but the date day names, represented by %a in the format string, stubbornly remain in their English form despite the documentation promising otherwise. :confused: