comparison piecrust/sources/base.py @ 27:105f24f490cb

Various fixes for the default page source: * Use forward slashes in ref paths * `auto_format` extensions should be stripped * Don't ignore pages with arbitrary extensions
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 19 Aug 2014 11:50:21 -0700
parents 617191dec18e
children 4bd840ae75cd
comparison
equal deleted inserted replaced
26:3701daa97927 27:105f24f490cb
304 for dirpath, dirnames, filenames in os.walk(self.fs_endpoint_path): 304 for dirpath, dirnames, filenames in os.walk(self.fs_endpoint_path):
305 rel_dirpath = os.path.relpath(dirpath, self.fs_endpoint_path) 305 rel_dirpath = os.path.relpath(dirpath, self.fs_endpoint_path)
306 dirnames[:] = list(filter(self._filterPageDirname, dirnames)) 306 dirnames[:] = list(filter(self._filterPageDirname, dirnames))
307 for f in filter(self._filterPageFilename, filenames): 307 for f in filter(self._filterPageFilename, filenames):
308 slug, ext = os.path.splitext(os.path.join(rel_dirpath, f)) 308 slug, ext = os.path.splitext(os.path.join(rel_dirpath, f))
309 slug = slug.replace('\\', '/')
310 if ext not in self.supported_extensions:
311 slug += ext
309 if slug.startswith('./') or slug.startswith('.\\'): 312 if slug.startswith('./') or slug.startswith('.\\'):
310 slug = slug[2:] 313 slug = slug[2:]
311 if slug == '_index': 314 if slug == '_index':
312 slug = '' 315 slug = ''
313 metadata = {'path': slug} 316 metadata = {'path': slug}
351 def _filterPageDirname(self, d): 354 def _filterPageDirname(self, d):
352 return not d.endswith('-assets') 355 return not d.endswith('-assets')
353 356
354 def _filterPageFilename(self, f): 357 def _filterPageFilename(self, f):
355 name, ext = os.path.splitext(f) 358 name, ext = os.path.splitext(f)
356 return (f[0] != '.' and 359 return (f[0] != '.' and # .DS_store and other crap
357 f[-1] != '~' and 360 f[-1] != '~' and # Vim temp files and what-not
358 ext.lstrip('.') in self.supported_extensions and 361 f not in ['Thumbs.db']) # Windows bullshit
359 f not in ['Thumbs.db'])
360 362
361 363
362 class DefaultPageSource(SimplePageSource, IPreparingSource, 364 class DefaultPageSource(SimplePageSource, IPreparingSource,
363 SimplePaginationSourceMixin): 365 SimplePaginationSourceMixin):
364 SOURCE_NAME = 'default' 366 SOURCE_NAME = 'default'