def init_env(self): """Initialize the environment for generating the Web site to deploy. This function reads the Web site configuration, sets up the template environment and sets object properties. """ self.dir_content = self.get_path('content', required=True) self.config = Config(self.get_path('site.yaml', required=True)) self.dir_templates = self.get_path('templates', required=True) self.template = Template(self) self.dir_bin = self.get_path('bin') # make all settings in site section available to templates for key, val in list(self.config.get_section('site').items()): self.template.add_var(key, val) # optional directory with static files like css, js and images self.dir_static = self.get_path('static') self.dir_dst = self.get_path('deploy') # feeds are only generated if base_url is set in site section of config self.base_url = self.config.get('site', 'base_url') if self.base_url is False: raise Exception('base_url not set in site config.')
def init_env(self): """Initialize the environment for generating the Web site to deploy. This function reads the Web site configuration, sets up the template environment and sets object properties. """ cwd = self.dir_site self.dir_content = path.join(cwd, 'content', required=True) self.config = config.load(path.join(cwd, 'site.yaml', required=True)) self.dir_templates = path.join(cwd, 'templates', required=True) self.template = Template(self) self.dir_bin = path.join(cwd, 'bin') # Make all settings in site section available to templates. self.template.vars.update(self.config['site']) # Optional directory with static files like css, js and images. self.dir_static = path.join(cwd, 'static') # Directory is created by the generate command. self.dir_deploy = path.join(cwd, 'deploy') self.base_url = self.config['site'].get('base_url') # base_url must be defined in settings if not self.base_url: raise Exception('base_url not set in site config.') # A dictionary of parsed documents indexed by resource paths. self.docs = {} # A dictionary of document collections. self.index = {} # A dictionary of collection names and distinct values. self.collections = {} # Set default templates once for a Logya instance. self.templates = { 'doc': self.config['content']['doc']['template'], 'index': self.config['content']['index']['template'], 'rss': self.config['content']['rss']['template'] } self.pages = {} # Set default pages for templates. for ctype, template in self.templates.items(): self.pages[ctype] = self.template.env.get_template(template) # Set languages if specified. if 'languages' in self.config: self.languages = self.config['languages'] # Map collection paths to config variables (vars) to make collection # settings accessible via index URLs. self.collection_index = { v['path']: k for k, v in self.config['collections'].items()}