Skip to content

Commit c34b8c5

Browse files
committed
Persist site
1 parent 7f20d16 commit c34b8c5

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

.github/workflows/postprocess.yml

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
run: python reindex_postprocess.py
2121
- name: Run PWA build
2222
run: python build_pwa.py
23+
env:
24+
PWA_HOME_PATH: /blueprints/
2325
- name: Run Prettier
2426
run: prettier --write blueprints/**/*.json
2527
- name: Check for uncommitted changes

build_pwa.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Define the base directory where blueprints are located
66
BLUEPRINTS_DIR = 'blueprints'
77
TEMPLATE_DIR = 'pwa-template'
8+
PWA_HOME_PATH = os.getenv('PWA_HOME_PATH', '/')
89

910
def read_template(file_path):
1011
with open(file_path, 'r') as file:
@@ -23,12 +24,14 @@ def build_pwa_for_folder(folder_path):
2324
# Extract necessary fields
2425
title = blueprint['meta']['title']
2526
description = blueprint['meta']['description']
26-
start_url = blueprint.get('landingPage', '/')
27+
start_url = PWA_HOME_PATH + folder_path + "/"
28+
slug = folder_path.split('/')[-1]
2729

2830
# Read and format index.html template
2931
index_html_template = read_template(os.path.join(TEMPLATE_DIR, 'index.html'))
3032
index_html_content = index_html_template.replace('{{PWA_NAME}}', title)\
31-
.replace('{{BLUEPRINT}}', json.dumps(blueprint, indent=2))
33+
.replace('{{BLUEPRINT}}', json.dumps(blueprint, indent=2))\
34+
.replace('{{PWA_SLUG}}', slug)
3235

3336
with open(os.path.join(folder_path, 'index.html'), 'w') as f:
3437
f.write(index_html_content)

pwa-template/index.html

+27-15
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
<link rel="manifest" href="manifest.json" />
77
<style>
88
:root {
9-
--header-height: 55px;
9+
--header-height: 39px;
10+
--header-padding: 8px;
1011
}
1112

1213
body {
@@ -19,7 +20,7 @@
1920
display: flex;
2021
justify-content: space-between;
2122
align-items: center;
22-
padding: 8px;
23+
padding: var(--header-padding);
2324
background-color: #1e2327;
2425
}
2526

@@ -44,7 +45,7 @@
4445

4546
#wp {
4647
width: 100%;
47-
height: calc(100vh - var(--header-height));
48+
height: calc(100vh - var(--header-height) - (2 * var(--header-padding)));
4849
border: 0;
4950
}
5051

@@ -74,11 +75,7 @@
7475
window.addEventListener("beforeinstallprompt", (event) => {
7576
event.preventDefault();
7677
installPrompt = event;
77-
if (isInstallHeaderHidden()) {
78-
hideInstallHeader();
79-
} else {
80-
showInstallHeader();
81-
}
78+
showInstallHeader();
8279
});
8380
installButton.addEventListener("click", async () => {
8481
if (!installPrompt) {
@@ -89,15 +86,8 @@
8986
hideInstallHeader();
9087
});
9188
closeInstallButton.addEventListener("click", () => {
92-
saveHideInstallHeader();
9389
hideInstallHeader();
9490
});
95-
function saveHideInstallHeader() {
96-
localStorage.setItem("hideInstallHeader", "true");
97-
}
98-
function isInstallHeaderHidden() {
99-
return localStorage.getItem("hideInstallHeader") === "true";
100-
}
10191
function hideInstallHeader() {
10292
document.body.classList.add("hide-install-header");
10393
}
@@ -107,12 +97,34 @@
10797

10898
// Boot Playground
10999
import { startPlaygroundWeb } from "https://playground.wordpress.net/client/index.js";
100+
const slug = "{{PWA_SLUG}}";
101+
102+
function isWordPressInstalled(slug) {
103+
return localStorage.getItem(`wordpress-installed-for-${slug}`) === 'true';
104+
}
105+
function setWordPressInstalled(slug) {
106+
localStorage.setItem(`wordpress-installed-for-${slug}`, 'true');
107+
}
108+
const shouldInstallWordPress = !isWordPressInstalled(slug);
110109
const client = await startPlaygroundWeb({
111110
iframe: document.getElementById("wp"),
112111
remoteUrl: `https://playground.wordpress.net/remote.html`,
112+
mounts: [
113+
{
114+
mountpoint: '/wordpress',
115+
device: {
116+
type: 'opfs',
117+
path: `/pwa-sites/${slug}`,
118+
},
119+
},
120+
],
121+
shouldInstallWordPress,
113122
blueprint: {{BLUEPRINT}}
114123
});
115124
await client.isReady();
125+
if (shouldInstallWordPress) {
126+
setWordPressInstalled(slug);
127+
}
116128
</script>
117129
</body>
118130
</html>

0 commit comments

Comments
 (0)