#!/usr/bin/python3
"""
In Pelican, compile a single source file (given as the command line
argument).

Distributed under CC-0.
"""
import functools
import sys

import pelican
from pelican import contents, generators, readers, writers

def main(source_path):
	settings = pelican.read_settings("pelicanconf.py")
	writer = writers.Writer(settings["OUTPUT_PATH"], settings)
	reader = readers.RstReader(settings)

	artgen = generators.ArticlesGenerator(
		settings.copy(), settings,
		settings["PATH"], settings["THEME"], settings["OUTPUT_PATH"])
	artgen.translations = []

	content, metadata = reader.read(source_path)
	art = contents.Article(content, metadata, 
		source_path=source_path, settings=settings)
	artgen.articles = [art]

	artgen.generate_articles(
		functools.partial(writer.write_file, relative_urls=True))


if __name__=="__main__":
	main(sys.argv[1])