B
    ‹æ@\X  ã               @   sr   d Z ddlmZmZmZmZ ddlZe e¡Z	ddl
mZ ddlmZ ddlmZ dZdd	„ Zd
d„ Zdd„ ZdS )a¼   Generate a ``sitemap.txt`` to aid with search indexing.

``sitemap.txt`` is a plain text list of all the pages in the docs site.
Each URL is listed on a line in the text file. It is machine readable
and used by search engines to know what pages are available for indexing.

All that is required to generate the sitemap is to list this module
``bokeh.sphinxext.sitemap`` in the list of extensions in the Sphinx
configuration file ``conf.py``.

é    )Úabsolute_importÚdivisionÚprint_functionÚunicode_literalsN)Újoin)ÚSphinxError)Ústatus_iterator)Úbuild_finishedÚhtml_page_contextÚsetupc             C   s0   |d }|d }| j  || d | d ¡ dS )zB Collect page names for the sitemap as HTML pages are built.

    ZSITEMAP_BASE_URLÚversionú/z.htmlN)Úsitemap_linksÚadd)ÚappZpagenameZtemplatenameÚcontextZdoctreeZsiter   © r   ú<lib/python3.7/site-packages/bokeh/sphinxext/bokeh_sitemap.pyr
   :   s    r
   c          
   C   s   t | jdƒ}tt| jƒddt| jƒƒ}y6t|dƒ"}x|D ]}| d| ¡ q:W W dQ R X W n. tk
rŠ } zt	d| ƒ‚W dd}~X Y nX dS )zE Generate a ``sitemap.txt`` from the collected HTML page links.

    zsitemap.txtzadding links to sitemap... ZbrownÚwz%s
Nz$cannot write sitemap.txt, reason: %s)
r   Zoutdirr   Úsortedr   ÚlenÚopenÚwriteÚOSErrorr   )r   Z	exceptionÚfilenameZ
links_iterÚfÚlinkÚer   r   r   r	   B   s    

 r	   c             C   s$   |   dt¡ |   dt¡ tƒ | _d S )Nzhtml-page-contextzbuild-finished)Zconnectr
   r	   Úsetr   )r   r   r   r   r   T   s    r   )Ú__doc__Z
__future__r   r   r   r   ZloggingZ	getLoggerÚ__name__ÚlogÚos.pathr   Zsphinx.errorsr   Zsphinx.utilr   Ú__all__r
   r	   r   r   r   r   r   Ú<module>   s   
	