def populate(self, site): ret = [] nodes = [node for node in self.parent if node.is_page] if page_order.upper() == 'DESC': 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) Registry.configurate(source_path, page_config) more_page_config = self.config.get('pages', {}).get(page_index, None) 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'] Registry.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 build_node(config, source_path, target_path, file_name): source_file = os.path.join(source_path, file_name) config = Registry.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 populate(self, site): pages = site.pages(recursive=True) categories = {} for page in pages: if not page['category']: continue if page.category not in categories: config = self.config_copy() target_name = re.sub(r'[\W -]+', '_', page.category, re.UNICODE) config['name'] = target_name config['target_name'] = target_name + config['html_extension'] Registry.configurate(CategoryDetail.source_path, config) categories[page.category] = CategoryDetail(config, self.target_folder, page.category) categories[page.category].count += 1 categories[page.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 processor(config, source_path, target_path): Registry.configurate(source_path, config) categories_name = config.get('name', 'categories') folder_config = config.copy() folder_config['target_name'] = categories_name folder_config['name'] = categories_name Registry.configurate(source_path, folder_config) folder = FolderNode(folder_config, None, target_path) 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' Registry.configurate(os.path.join(source_path, index_config['target_name']), 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, )