Example #1
0
def quickstart(location: str, title: Optional[str]):
    path = Path(location)
    path.mkdir(parents=True, exist_ok=True)

    abs_out = os.path.abspath(path)
    if not title:
        title = Path(abs_out).name
    title_slug = slugify_title(title)

    template_location = Path(__file__).parent / 'project-template'

    with directory(template_location), custom_jinja_tags():
        site = Site(url="https://example.com/", title=title)

        [site.add(str(p), jinja(p)) for p in paths('_templates_/**/*.html')]
        [site.add(str(p), jinja(p)) for p in paths('*.html')]
        site.add('website.py', jinja('website.py.j2', title_slug=title_slug))
        site.add('requirements.txt',
                 jinja('requirements.txt.j2', version=lw_version()))
        site.add('posts')
        [
            site.add(str(p), jinja(p)) for p in paths('styles/**/*css')
            if p.name != 'attributes.scss'
        ]
        site.add('styles/attributes.scss',
                 jinja('styles/attributes.scss', accent=Color.bright()))
        site.add('js')
        site.add('img')

        site.generate(abs_out)

        website_file = os.path.join(abs_out, 'website.py')
        os.chmod(website_file,
                 stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)  # -rwxr--r--

    logger.info(f' Project initialized in: {abs_out}')
Example #2
0
def test_dir():
    assert set(paths('resources/glob')) == {Path('resources/glob')}
Example #3
0
def test_path():
    assert set(paths(
        Path('resources/test.html'))) == {Path('resources/test.html')}
Example #4
0
def test_recursive_files():
    assert set(paths('resources/glob/**/*.md')) == {
        Path('resources/glob/a.md'),
        Path('resources/glob/b.md'),
        Path('resources/glob/dir/1.md')
    }
Example #5
0
def test_files():
    assert set(paths('resources/glob/*.html')) == {
        Path('resources/glob/a.html'),
        Path('resources/glob/b.html')
    }
Example #6
0
def test_file():
    assert set(paths('resources/glob/a.md')) == {Path('resources/glob/a.md')}