def _create(self, rawtitle): """Create a page with this title, if it doesn't exist. This method first checks whether a page with the same slug (sanitized name) exists_on_disk. If it does, it doesn't do antyhing. Otherwise, the relevant attributes are created. Nothing is written to disc (to the source file). You must call the write_page method to do that. Doing it this way, after creation you can call a method to add random text, for example, before committing the page to disk. """ slug = util.make_slug(rawtitle) if self.site.page_exists_on_disk(slug): raise ValueError #print "Attempted to create a page which already exists." #return False self._title = unicode(rawtitle,"UTF-8") self._slug = slug self._dirs['source_dir'] = os.path.join(self.site.dirs['source'], slug) self._dirs['source_filename'] = os.path.join(self._dirs['source_dir'], slug + '.md') self._dirs['www_dir'] = os.path.join(self.site.dirs['www'], slug) self._dirs['www_filename'] = os.path.join(self._dirs['www_dir'], \ 'index.html') self._config = self._create_config() return True
def _create(self, rawtitle): """Create a page with this title, if it doesn't exist. This method first checks whether a page with the same slug (sanitized name) exists_on_disk. If it does, it doesn't do antyhing. Otherwise, the relevant attributes are created. Nothing is written to disc (to the source file). You must call the write_page method to do that. Doing it this way, after creation you can call a method to add random text, for example, before committing the page to disk. """ slug = util.make_slug(rawtitle) if self.site.page_exists_on_disk(slug): raise ValueError #print "Attempted to create a page which already exists." #return False self._title = unicode(rawtitle, "UTF-8") self._slug = slug self._dirs['source_dir'] = os.path.join(self.site.dirs['source'], slug) self._dirs['source_filename'] = os.path.join(self._dirs['source_dir'], slug + '.md') self._dirs['www_dir'] = os.path.join(self.site.dirs['www'], slug) self._dirs['www_filename'] = os.path.join(self._dirs['www_dir'], \ 'index.html') self._config = self._create_config() return True
def rename(self, new_title): """Rename an existing s2 page. For an existing s2 page, updates the directory and file name, as well as the internal configuration information (since it contains the title and the slug) """ if not isinstance(new_title, str) and \ not isinstance(new_title, unicode): raise TypeError # print "Cannot rename page. New title must be string or unicode." new_slug = util.make_slug(new_title) if self.site.page_exists_on_disk(new_slug): raise ValueError # print "Cannot rename page. A page with the same \ # title/slug already exists." #wipe the source directory for this page shutil.rmtree(self._dirs['source_dir']) #just change dirinfo, config, and write self._title = new_title self._slug = new_slug self._config['title'] = [self._title] self._config['slug'] = [self._slug] self._dirs['source_dir'] = os.path.join(self.site.dirs['source'], new_slug) self._dirs['source_filename'] = os.path.join(self._dirs['source_dir'], new_slug + '.md') self._dirs['www_dir'] = os.path.join(self.site.dirs['www'], new_slug) #self._dirs['www_filename'] = os.path.join(self._dirs['www_dir'], \ # new_slug + '.html') self.write()