add indentation support to generator script

This commit is contained in:
Crispy 2022-01-18 22:17:50 +01:00
parent aff25868d2
commit 767f249413
7 changed files with 48 additions and 46 deletions

View file

@ -6,7 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/style.css"> <link rel="stylesheet" href="/style.css">
<link rel="icon" type="image/x-icon" href="/icons/favicon.png"> <link rel="icon" type="image/x-icon" href="/icons/favicon.png">
<title>CrispyPin.cc - Fractals</title> <title>CrispyPin.cc - Fractals</title>
</head> </head>
<body> <body>
@ -16,7 +15,7 @@
<nav> <nav>
<ul> <ul>
<li><a href="/">Home</a></li> <li><a href="/">Home</a></li>
<li><a href="/games/">Games</a></li> <li><a href="https://crispypin.itch.io/">Games</a></li>
<li><a href="/fractals/">Fractals</a></li> <li><a href="/fractals/">Fractals</a></li>
<li><a href="/blender/">Blender stuff</a></li> <li><a href="/blender/">Blender stuff</a></li>
<li><a href="https://crispypin.github.io/gol-wallpaper">Game of Life</a></li> <li><a href="https://crispypin.github.io/gol-wallpaper">Game of Life</a></li>

View file

@ -6,7 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/style.css"> <link rel="stylesheet" href="/style.css">
<link rel="icon" type="image/x-icon" href="/icons/favicon.png"> <link rel="icon" type="image/x-icon" href="/icons/favicon.png">
<title>CrispyPin.cc</title> <title>CrispyPin.cc</title>
</head> </head>
<body> <body>
@ -16,7 +15,7 @@
<nav> <nav>
<ul> <ul>
<li><a href="/">Home</a></li> <li><a href="/">Home</a></li>
<li><a href="/games/">Games</a></li> <li><a href="https://crispypin.itch.io/">Games</a></li>
<li><a href="/fractals/">Fractals</a></li> <li><a href="/fractals/">Fractals</a></li>
<li><a href="/blender/">Blender stuff</a></li> <li><a href="/blender/">Blender stuff</a></li>
<li><a href="https://crispypin.github.io/gol-wallpaper">Game of Life</a></li> <li><a href="https://crispypin.github.io/gol-wallpaper">Game of Life</a></li>

View file

@ -38,14 +38,18 @@ def ensure_dir(filepath: str):
def apply_include(contents: str) -> str: def apply_include(contents: str) -> str:
included_file = get_included_name(contents) included_file = get_included_name(contents)
inserted_text = read_file(TEMPLATE_DIR + included_file)
new_contents = read_file(TEMPLATE_DIR + included_file)
return insert_contents(contents, new_contents)
def insert_contents(contents, new_contents):
index_start, index_end = get_marker_indices(contents) index_start, index_end = get_marker_indices(contents)
return contents[:index_start] + new_contents + contents[index_end + len(INCLUDE_MARKER_END):] index_end += len(INCLUDE_MARKER_END)
prefix = contents[:index_start]
suffix = contents[index_end:]
indent = prefix.split("\n")[-1]
inserted_text = inserted_text.replace("\n", "\n" + indent)
return prefix + inserted_text + suffix
def get_included_name(contents): def get_included_name(contents):

View file

@ -1,7 +1,7 @@
<nav> <nav>
<ul> <ul>
<li><a href="/">Home</a></li> <li><a href="/">Home</a></li>
<li><a href="/games/">Games</a></li> <li><a href="https://crispypin.itch.io/">Games</a></li>
<li><a href="/fractals/">Fractals</a></li> <li><a href="/fractals/">Fractals</a></li>
<li><a href="/blender/">Blender stuff</a></li> <li><a href="/blender/">Blender stuff</a></li>
<li><a href="https://crispypin.github.io/gol-wallpaper">Game of Life</a></li> <li><a href="https://crispypin.github.io/gol-wallpaper">Game of Life</a></li>