def populate(self, site): if not CategoryDetail.source_paths: raise NotImplementedError('No CategoryDetail.source_paths were not assigned. ' 'Create a node of type "category_detail"') pages = site.pages(recursive=True) categories = {} for page in pages: try: category = page.category except AttributeError: continue if category not in categories: config = self.config_copy() target_name = re.sub(r'[\W -]+', '_', category, re.UNICODE) config['name'] = target_name config['target_name'] = target_name + config['html_extension'] config['title'] = category source_path = CategoryDetail.source_paths.get(category, CategoryDetail.source_paths.get(None)) if not source_path: raise NotImplementedError('No CategoryDetail page has been ' 'registered for the "%s" category, and there is no ' 'default page either' % category) configurate(source_path, config) categories[category] = CategoryDetail(config, source_path, self.target_folder) categories[category].count += 1 categories[category].pages.append(page) # assign categories list to the category index page if CategoryDetail.index_node: CategoryDetail.index_node.config.setdefault('categories', categories.values()) self.replace_with(categories.values())
def index_processor(config, source_path, target_path): config = configurate(source_path, config) categories_name = config['name'] folder_config = config.copy() folder_config['target_name'] = categories_name folder_config['name'] = categories_name folder_config['type'] = config['default_folder_type'] folder = build_node(folder_config, os.path.dirname(source_path), target_path, categories_name)[0] categories_folder_target_path = os.path.join(target_path, categories_name) config['dont_inherit'] = [ key for key in config['dont_inherit'] if key != 'title' ] index_config = config.copy() index_config['target_name'] = config['index.html'] index_config['name'] = 'index' configurate(os.path.join(source_path, config['index.html']), index_config) index_node = JinjaNode(index_config, source_path, categories_folder_target_path) folder.append(index_node) CategoryDetail.index_node = index_node # attach Processor node - this is the class that will scan the pages for # the `category` property: folder.append( CategoryFolderProcesser(config, categories_folder_target_path)) return (folder, )
def populate(self, site): ret = [] nodes = [node for node in self.siblings if node.is_page] if page_reverse: nodes.reverse() pages = paginate(nodes, page_limit) first_page = None last_page = None for page in pages: if not len(ret): # is this the first page? page_config = self.config_copy( True) # copy *all* config, even name and title. else: name = "%s%i" % (page_name, 1 + len(ret)) target_name = name + config['html_extension'] page_config = self.config_copy( name=name, target_name=target_name, ) # page configuration can be further customized by creating a # pages: {} dictionary. The key names should be the page index page_index = 1 + len(ret) page_config.setdefault('title', "%s %i" % (page_title, page_index)) page_config.setdefault('page', page) page_config.setdefault('iterable', False) configurate(source_path, page_config) more_page_config = self.config.get('pages', {}).get(page_index) if more_page_config: page_config.update(more_page_config) node = JinjaNode(page_config, source_path, target_path) # now that we have node objects we can assign prev and next properties onto # the page object. page.prev = last_page page.next = None if last_page: last_page.page.next = node ret.append(node) last_page = node for node in ret: node.page.first = first_page node.page.last = last_page return ret
def populate(self, site): ret = [] nodes = [node for node in self.siblings if node.is_page] if page_reverse: nodes.reverse() pages = paginate(nodes, page_limit) first_page = None last_page = None for page in pages: if not len(ret): # is this the first page? page_config = self.config_copy(True) # copy *all* config, even name and title. else: name = "%s%i" % (page_name, 1 + len(ret)) target_name = name + config['html_extension'] page_config = self.config_copy( name=name, target_name=target_name, ) # page configuration can be further customized by creating a # pages: {} dictionary. The key names should be the page index page_index = 1 + len(ret) page_config.setdefault('title', "%s %i" % (page_title, page_index)) page_config.setdefault('page', page) page_config.setdefault('iterable', False) configurate(source_path, page_config) more_page_config = self.config.get('pages', {}).get(page_index) if more_page_config: page_config.update(more_page_config) node = JinjaNode(page_config, source_path, target_path) # now that we have node objects we can assign prev and next properties onto # the page object. page.prev = last_page page.next = None if last_page: last_page.page.next = node ret.append(node) last_page = node for node in ret: node.page.first = first_page node.page.last = last_page return ret
def processor(config, source_path, target_path): """ If 'thumbnails' or 'thumbnail' has been set, thumbnails will be generated. Examples: thumbnail: 75x150 # one thumbnail, specifying width and height as a string thumbnails: # multiple thumbnails, by name medium: [200, 200] # array of [width, height] large: 1000 # max dimension for both width and height thumbnails: # multiple thumbnails by index - 200 # this will be image_node.thumbnail - 1000 # this will be image_node.thumbnail_2 """ image_node = ImageNode(config, source_path, target_path) if 'thumbnail' in config and 'thumbnails' not in config: config['thumbnails'] = {'thumbnail': config['thumbnail']} if 'thumbnails' not in config: return (image_node,) thumbs = [] thumb_index = 0 for thumbnail in config['thumbnails']: if isinstance(config['thumbnails'], list): thumb_index += 1 size = thumbnail thumbnail = thumb_index = 1 and 'thumbnail' or 'thumbnail_' + thumb_index else: size = config['thumbnails'][thumbnail] target_name, ext = os.path.splitext(image_node.target_name) target_name += '_' + thumbnail target_name += ext thumb_config = image_node.config_copy(name=thumbnail, target_name=target_name) thumb_config['size'] = size thumb_config['iterable'] = False thumb_config['is_thumbnail'] = True thumb_config['skip'] = config['skip'] configurate(os.path.join(source_path, target_name), thumb_config) thumbnail_node = ImageNode(thumb_config, source_path, target_path) image_node.config[thumbnail] = thumbnail_node thumbs.append(thumbnail_node) return (image_node, ) + tuple(thumbs)
def processor(config, source_path, target_path): """ If 'thumbnails' or 'thumbnail' has been set, thumbnails will be generated. Examples: thumbnail: 75x150 # one thumbnail, specifying width and height as a string thumbnails: # multiple thumbnails, by name medium: [200, 200] # array of [width, height] large: 1000 # max dimension for both width and height thumbnails: # multiple thumbnails by index - 200 # this will be image_node.thumbnail - 1000 # this will be image_node.thumbnail_2 """ image_node = ImageNode(config, source_path, target_path) if 'thumbnail' in config and 'thumbnails' not in config: config['thumbnails'] = {'thumbnail': config['thumbnail']} if 'thumbnails' not in config: return (image_node,) thumbs = [] thumb_index = 0 for thumbnail in config['thumbnails']: if isinstance(config['thumbnails'], list): thumb_index += 1 size = thumbnail thumbnail = thumb_index = 1 and 'thumbnail' or 'thumbnail_' + thumb_index else: size = config['thumbnails'][thumbnail] target_name, ext = os.path.splitext(image_node.target_name) target_name += '_' + thumbnail target_name += ext thumb_config = image_node.config_copy(name=thumbnail, target_name=target_name) thumb_config['size'] = size thumb_config['iterable'] = False thumb_config['is_thumbnail'] = True thumb_config['skip'] = config['skip'] configurate(os.path.join(source_path, target_name), thumb_config) thumbnail_node = ImageNode(thumb_config, source_path, target_path) image_node.config[thumbnail] = thumbnail_node thumbs.append(thumbnail_node) return (image_node, ) + tuple(thumbs)
def populate(self, site): if not CategoryDetail.source_paths: raise NotImplementedError( 'No CategoryDetail.source_paths were not assigned. ' 'Create a node of type "category_detail"') pages = site.pages(recursive=True) categories = {} for page in pages: try: category = page.category except AttributeError: continue if category not in categories: config = self.config_copy() target_name = re.sub(r'[\W -]+', '_', category, re.UNICODE) config['name'] = target_name config['target_name'] = target_name + config['html_extension'] config['title'] = category source_path = CategoryDetail.source_paths.get( category, CategoryDetail.source_paths.get(None)) if not source_path: raise NotImplementedError( 'No CategoryDetail page has been ' 'registered for the "%s" category, and there is no ' 'default page either' % category) configurate(source_path, config) categories[category] = CategoryDetail(config, source_path, self.target_folder) categories[category].count += 1 categories[category].pages.append(page) categories_values = list(categories.values()) # assign categories list to the category index page if CategoryDetail.index_node: CategoryDetail.index_node.config.setdefault( 'categories', categories_values) self.replace_with(categories_values)
def build_node(config, source_path, target_path, file_name): source_file = os.path.abspath(os.path.join(source_path, file_name)) config = configurate(source_file, config) if not config: return # create node(s). if you specify a 'type' it will override the default. # built-in types are 'page', 'folder', and 'asset' processor = config['type'] return Registry.nodes(processor, config, source_file, target_path)
def build_node(config, source_path, target_path, file_name): source_file = os.path.abspath(os.path.join(source_path, file_name)) config = configurate(source_file, config) if not config: return # create node(s). if you specify a 'type' it will override the default. # built-in types are 'page', 'folder', and 'asset' processor = config["type"] return Registry.nodes(processor, config, source_file, target_path)
def detail_processor(config, source_path, target_path): # just store the source path - when the detail pages get created, they # will use this path. config = configurate(source_path, config) if 'category' in config: register_category_page(config['category'], source_path) elif 'categories' in config: for category in config['categories']: register_category_page(category, source_path) else: register_category_page(None, source_path) return ()
def detail_processor(config, source_path, target_path): # just store the source path - when the detail pages get created, they # will use this path. config = configurate(source_path, config) if 'category' in config: register_category_page(config['category'], source_path) elif 'categories' in config: for category in config['categories']: register_category_page(category, source_path) else: register_category_page(None, source_path) return ()
def index_processor(config, source_path, target_path): config = configurate(source_path, config) categories_name = config['name'] folder_config = config.copy() folder_config['target_name'] = categories_name folder_config['name'] = categories_name folder_config['type'] = config['default_folder_type'] folder = build_node(folder_config, os.path.dirname(source_path), target_path, categories_name)[0] categories_folder_target_path = os.path.join(target_path, categories_name) config['dont_inherit'] = [key for key in config['dont_inherit'] if key != 'title'] index_config = config.copy() index_config['target_name'] = config['index.html'] index_config['name'] = 'index' configurate(os.path.join(source_path, config['index.html']), index_config) index_node = JinjaNode(index_config, source_path, categories_folder_target_path) folder.append(index_node) CategoryDetail.index_node = index_node # attach Processor node - this is the class that will scan the pages for # the `category` property: folder.append(CategoryFolderProcesser(config, categories_folder_target_path)) return (folder, )