def build_index(self, mode=None): """Build index of documents for content directories to be created. The mode argument hints the Logya command that was executed.""" msg_duplicate = 'The URL {} is already used and will be overwritten.' for doc in DocReader(self.dir_content).parsed: url = doc['url'] # Warn user about duplicate URLs when not in serve mode. if 'serve' != mode and url in self.docs: print(msg_duplicate.format(url)) self.docs[url] = doc self.update_index(doc) # For each collection sort docs by creation dates in descending order. for url, collection in self.index.items(): collection.docs.sort(key=itemgetter('created'), reverse=True) # Make index available to templates. self.template.vars['index'] = self.index # Make collections values unique and turn list of attribute values into path, value tuples. for coll_path, name in self.collection_index.items(): values = [] for val in sorted(set(self.collections.get(name, []))): url = '/{}/{}/'.format(coll_path, path.slugify(val)) values.append((url, val)) if values: self.collections[name] = values # Make collections available to templates. self.template.vars['collections'] = self.collections
def test_slugify(self): tests = [('FOSDEM', 'fosdem'), ('Video Demonstration', 'video-demonstration'), ('Chrome OS', 'chrome-os')] for test_input, expected in tests: self.assertEqual(expected, path.slugify(test_input))
def test_slugify(self): tests = [('FOSDEM', 'fosdem'), ('Video Demonstration', 'video-demonstration'), ('Chrome OS', 'chrome-os')] for test in tests: self.assertEqual(test[1], path.slugify(test[0]))
def test_slugify(self): tests = [ ('FOSDEM', 'fosdem'), ('Video Demonstration', 'video-demonstration'), ('Chrome OS', 'chrome-os')] for test_input, expected in tests: self.assertEqual(expected, path.slugify(test_input))
def test_slugify(self): tests = [ ('FOSDEM', 'fosdem'), ('Video Demonstration', 'video-demonstration'), ('Chrome OS', 'chrome-os')] for test in tests: self.assertEqual(test[1], path.slugify(test[0]))
def _update_doc_index(self, doc, attr, basepath): """Add the doc to the index defined for the attribute.""" for val in doc[attr]: url = '/{}/{}/'.format(basepath, path.slugify(val)) links = attr + '_links' doc[links] = doc.get(links, []) + [(url, val)] # Must append file name to url to create subdir. self._update_index(doc, url + self.index_filename)
def _update_doc_index(self, doc, var, basepath): """Add the doc to the index defined for the header variable (var).""" for val in doc[var]: url = '/{}/{}/'.format(basepath, path.slugify(val)) links = var + '_links' doc[links] = doc.get(links, []) + [(url, val)] # Must append file name to url to create subdir. self._update_index(doc, url + self.index_filename)
if body: body.append(resources) doc = { 'created': datetime.now(), 'description': body[0].split('. ')[0] + '.', 'groups': groups, 'muscles': muscles, 'template': 'exercise.html', 'title': name, 'variants': variants } # Files shall be saved as md files, so calling write_content directly # is not possible as it would save as html. filename = target_file(logya.dir_content, '/exercise/{}.md'.format(slugify(name))) if not os.path.exists(filename): write(filename, encode_content(doc, '\n\n'.join(body))) # Create stub files for variants for variant in variants: filename = target_file(logya.dir_content, '/exercise/{}.md'.format(slugify(variant))) if not os.path.exists(filename): ex_variants = list(set(variants).union(set([name])).difference(set([variant]))) doc = { 'created': datetime.now(), 'description': '', 'groups': groups, 'muscles': muscles, 'template': 'exercise.html', 'title': variant,
if body: body.append(resources) doc = { 'created': datetime.now(), 'description': body[0].split('. ')[0] + '.', 'groups': groups, 'muscles': muscles, 'template': 'exercise.html', 'title': name, 'variants': variants } # Files shall be saved as md files, so calling write_content directly # is not possible as it would save as html. filename = target_file(logya.dir_content, '/exercise/{}.md'.format(slugify(name))) if not os.path.exists(filename): write(filename, encode_content(doc, '\n\n'.join(body))) # Create stub files for variants for variant in variants: filename = target_file(logya.dir_content, '/exercise/{}.md'.format(slugify(variant))) if not os.path.exists(filename): ex_variants = list( set(variants).union(set([name])).difference(set([variant ]))) doc = { 'created': datetime.now(), 'description': '', 'groups': groups,