Merge branch 'sandpoints_theme' of https://git.memoryoftheworld.org/PirateCare/Syllabus into sandpoints_theme

This commit is contained in:
Marcell Mars 2020-09-08 21:09:49 +02:00
commit 3497a2d3c6
3 changed files with 34 additions and 17 deletions

View File

@ -9,7 +9,6 @@ python "D:\dev\websites\sandpoints-dev\custom_syadmin\git_hooks_post-receive.py"
--git_repo "D:\dev\websites\pirate-care-syllabus\gitea\gitea-repositories\gitea\pirate-care-syllabus.git" \
--website "D:\dev\websites\testing-ground\sandpoints" \
--website_preview "D:\dev\websites\testing-ground\sandpoints\_preview" \
--hugo_preview_url http://localhost:8000/_preview/ \
--library "D:\dev\websites\pirate-care-syllabus\_library" \
--tmp_dir "D:\tmp\tmp"
--oldrev $oldrev \
@ -22,7 +21,7 @@ python "D:\dev\websites\sandpoints-dev\custom_syadmin\git_hooks_post-receive.py"
Just a mental note to read refs from the post-receive hook like this:
oldrev,newrev,refname = sys.stdin.readline().strip().split( )
oldrev,newrev,refname = sys.stdin.readline().strip().split(' ')
"""
import os
@ -53,6 +52,7 @@ vars = {
'tmp_dir': '/tmp',
'force': False,
'branch': None,
'preview_branch': None,
}
# logging time
@ -83,14 +83,20 @@ def cmd(parts, cwd=None, env=None):
return subprocess.check_output(parts, cwd=cwd, env=env, universal_newlines=True).strip()
def rmrf(path):
def rmrf(path, keep_dir=False):
""" Use safe-rm for recursive removal """
""" @TODO: make it safer """
def remove_readonly(func, path, excinfo):
os.chmod(path, stat.S_IWRITE)
func(path)
# Try removal
if os.path.exists(path) and len(os.path.realpath(path)) > 1:
if keep_dir and os.path.exists(path) and len(os.path.realpath(path)) > 1:
for root, dirs, files in os.walk(path):
for f in files:
os.unlink(os.path.join(root, f))
for d in dirs:
shutil.rmtree(os.path.join(root, d), onerror=remove_readonly)
elif os.path.exists(path) and len(os.path.realpath(path)) > 1:
shutil.rmtree(path, onerror=remove_readonly)
else:
print("Either the path doesn't exist or you are trying to delete the root directory(?!):", path)
@ -108,12 +114,19 @@ def build_site(dest, tmp, branch=None, hugo_environment='gitea'):
global GIT_PATH, GIT_REPO, HUGO_PATH
if branch:
print("Cloning branch: ", branch)
cmd([GIT_PATH, 'clone', '--single-branch', '--branch', branch, '.', tmp], cwd=GIT_REPO)
cmd([GIT_PATH, 'clone', '--branch', branch, '.', tmp], cwd=GIT_REPO)
#print(' '.join([GIT_PATH, 'archive', '--format', 'tar', branch, '|', 'tar', '-x', '-C', tmp]))
#subprocess.call(' '.join([GIT_PATH, 'archive', '--format', 'tar', branch, '|', 'tar', '-x', '-C', tmp]), shell=True, cwd=GIT_REPO)
else:
cmd([GIT_PATH, 'clone', '.', tmp], cwd=GIT_REPO)
rmrf(dest)
rmrf(os.path.join(tmp, '.git'))
rmrf(dest, keep_dir=True)
try:
os.makedirs(dest, exist_ok=True)
if not os.path.exists(dest):
os.makedirs(dest)
print("Build destination created: ", dest)
else:
print("Build destination exists: ", dest)
except:
print(f"Error creating the directory: {dest}")
lcl = f'{tmp}/last-commit-log.txt'
@ -129,7 +142,6 @@ def build_site(dest, tmp, branch=None, hugo_environment='gitea'):
now_time = datetime.now().strftime(date_format)
clobber(lcl, f"\n{start_time}\n{now_time}", append=True)
shutil.move(lcl, dest)
rmrf(tmp)
# Parsing command line arguments
@ -156,19 +168,23 @@ published = False
refs = cmd([GIT_PATH, 'diff-tree', '--no-commit-id', '--name-only', REF], cwd=GIT_REPO).split("\n")
for r in refs:
if FORCE or r == "PUBLISH.trigger.md":
build_site(WEBSITE, TMP_WEBSITE)
build_site(WEBSITE, TMP_WEBSITE, branch=BRANCH)
published = True
# Check if there is a !publish!
if not published:
refs = cmd([GIT_PATH, 'show', '--format="%s"', '-s'], cwd=GIT_REPO).split(' ')
for r in refs:
if r == "!publish!":
build_site(WEBSITE, TMP_WEBSITE)
build_site(WEBSITE, TMP_WEBSITE, branch=BRANCH)
published = True
# Let the world know if there hasn't been a publish
if not published:
print("The site wasn't build because there was no publish trigger, nor was it forced.")
# create preview version
build_site(WEBSITE_PREVIEW, TMP_WEBSITE_PREVIEW, branch=BRANCH, hugo_environment='preview')
build_site(WEBSITE_PREVIEW, TMP_WEBSITE_PREVIEW, branch=PREVIEW_BRANCH, hugo_environment='preview')
# Clean up temp directories
rmrf(TMP_WEBSITE)
rmrf(TMP_WEBSITE_PREVIEW)
# @TODO: link the library

1
static/css/site.css Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,8 @@
{{ if eq hugo.Environment "gitea" }}
{{ if (or (eq hugo.Environment "gitea") (eq hugo.Environment "preview") ) }}
<link rel="stylesheet" href="/css/site.css">
{{ else if .Site.IsServer }}
{{ $style := resources.Get "css/site.css" | postCSS (dict "config" "./assets/css/postcss.config.js") | minify | fingerprint }}
<link rel="stylesheet" href="{{ $style.Permalink }}" integrity="{{ $style.Data.Integrity }}">
{{ $style := resources.Get "css/site.css" | postCSS (dict "config" "./assets/css/postcss.config.js") | minify }}
<link rel="stylesheet" href="{{ $style.Permalink }}">
{{ else }}
{{ $flist := newScratch }}
{{ $flist.Set "initial" "nop" }}
@ -21,7 +21,7 @@
{{ if in $css "css" }}
<link rel="stylesheet" href="{{ "/css/" }}{{ $css }}">
{{ else }}
{{ $style := resources.Get "css/site.css" | postCSS (dict "config" "./assets/css/postcss.config.js") | minify | fingerprint }}
<link rel="stylesheet" href="{{ $style.Permalink }}" integrity="{{ $style.Data.Integrity }}">
{{ $style := resources.Get "css/site.css" | postCSS (dict "config" "./assets/css/postcss.config.js") | minify }}
<link rel="stylesheet" href="{{ $style.Permalink }}">
{{ end }}
{{ end }}