Using an "edit" context instead of a separate "edit" subdomain

This commit is contained in:
echarp 2022-11-26 18:18:48 +01:00
parent cf5ae1bf82
commit a181c1837e
7 changed files with 32 additions and 40 deletions

View File

@ -5,34 +5,28 @@ ServerSignature Off
Protocols h2 h2c http/1.1 Protocols h2 h2c http/1.1
DocumentRoot /var/simpleWeb/apps/acoeur/public DocumentRoot /var/simpleWeb/apps/acoeur/public
<Location /author> Alias /edit /var/simpleWeb/apps/acoeur/content
<Directory /var/simpleWeb/apps/acoeur>
AuthUserFile /home/manu/Adata/.htaccessPasswords
AuthName "Quiz d'A Livr'Ouvert"
AuthType Basic
Require user mag manu amelie tiffany
</Directory>
<Directory /var/simpleWeb/apps/acoeur/*/users/*/>
Require all granted Require all granted
# Send back all headers, most importantly the eventual "authorization" one </Directory>
Header always echo <Directory /var/simpleWeb/apps/acoeur/public/ananke>
# Do not send a 404 Require all granted
Redirect 204 / </Directory>
<Directory /var/simpleWeb/apps/acoeur/public/assets>
# For development Require all granted
Header always set authorization "test" </Directory>
</Location> <Directory /var/simpleWeb/apps/acoeur/public/js>
</VirtualHost> Require all granted
</Directory>
<VirtualHost *:80> <Directory /var/simpleWeb/apps/acoeur/public/*.ico>
ServerName edit.acoeur
Protocols h2 h2c http/1.1
DocumentRoot /var/simpleWeb/apps/acoeur/content
<Directory /var/simpleWeb/apps/acoeur/content>
# This is special, anybody can see and edit it!
Require all granted Require all granted
</Directory> </Directory>
CustomLog /var/simpleWeb/log/apache/acoeur.log combined CustomLog /var/simpleWeb/log/apache/acoeur.log combined
# So that simple web editor can display eventual errors
Alias /app.log /var/simpleWeb/apps/acoeur/public/app.log
Header set Access-Control-Allow-Origin acoeur
Header set Access-Control-Allow-Methods "HEAD, GET, POST, PUT, OPTIONS, DELETE"
Header set Access-Control-Allow-Headers *
</VirtualHost> </VirtualHost>

View File

@ -6,6 +6,9 @@ line="$1"
url=$(echo "$line" | cut -d ' ' -f7) url=$(echo "$line" | cut -d ' ' -f7)
# Remove the starting "/edit" part, which is an apache alias required to target the proper directory
url=${url#/edit*}
full="$(pwd)/content$url" full="$(pwd)/content$url"
dir=${full%/*} dir=${full%/*}

View File

@ -1,8 +1,8 @@
/pages/doc/devoir.md:title: Devoir /pages/doc/devoir.md:title: Devoir
/pages/doc/intro.md:title: Introduction
/pages/doc/savoir.md:title: Savoir /pages/doc/savoir.md:title: Savoir
/pages/doc/vouloir.md:title: Vouloir /pages/doc/vouloir.md:title: Vouloir
/pages/doc/pouvoir.md:title: Pouvoir /pages/doc/pouvoir.md:title: Pouvoir
/pages/doc/intro.md:title: Introduction
/pages/1er-quiz/cff71434-fdaf-468f-838c-067059979299.md:title: Chapitre 3 - Les lettres de nulle part /pages/1er-quiz/cff71434-fdaf-468f-838c-067059979299.md:title: Chapitre 3 - Les lettres de nulle part
/pages/1er-quiz/b80fcc08-170e-4422-8498-ae1f97b47eda.md:title: Chapitre 5 - Le chemin de traverse /pages/1er-quiz/b80fcc08-170e-4422-8498-ae1f97b47eda.md:title: Chapitre 5 - Le chemin de traverse
/pages/1er-quiz/7c038015-c989-4024-a3cf-14b8557fdb0c.md:title: Chapitre 6 - Rendez-vous sur la voie 9 3/4 /pages/1er-quiz/7c038015-c989-4024-a3cf-14b8557fdb0c.md:title: Chapitre 6 - Rendez-vous sur la voie 9 3/4

View File

@ -10,7 +10,7 @@ document.querySelectorAll('aside#actions #create')
.forEach(elt => elt.onclick = () => { .forEach(elt => elt.onclick = () => {
const url = `${topSection}/${uuid()}` const url = `${topSection}/${uuid()}`
fetch(`${document.body.dataset.editHost}/${url}.create`, { method: 'PUT', body: topSection }) fetch(`/edit/${url}.create`, { method: 'PUT', body: topSection })
.then(() => sleep(1)) .then(() => sleep(1))
.then(() => window.location.assign('/' + url)) .then(() => window.location.assign('/' + url))
.catch(error => console.error(`Error creating #{topSection}`, error)) .catch(error => console.error(`Error creating #{topSection}`, error))
@ -37,7 +37,7 @@ document.querySelectorAll('aside#actions input#file')
document.querySelectorAll('.delete_image') document.querySelectorAll('.delete_image')
.forEach(elt => elt.onclick = () => { .forEach(elt => elt.onclick = () => {
if (confirm(elt.dataset.confirm)) if (confirm(elt.dataset.confirm))
fetch(document.body.dataset.editHost + elt.dataset.target, { method: 'DELETE' }) fetch('/edit/' + elt.dataset.target, { method: 'DELETE' })
.then(() => elt.parentNode.remove())
.catch(error => console.error(error)) .catch(error => console.error(error))
.finally(() => elt.parentNode.remove())
}) })

View File

@ -18,7 +18,7 @@ const pages = document.getElementById('pages')
prepareChoiceEdition = (node) => { prepareChoiceEdition = (node) => {
// Load list of pages from which authors can select results' page // Load list of pages from which authors can select results' page
if (node.list && !node.dataset.old && !pages.children.length) if (node.list && !node.dataset.old && !pages.children.length)
fetch(`${editHost}/pages.txt`, { cache: 'no-store' }) fetch('/pages.txt', { cache: 'no-store' })
.then(pages => pages.text()) .then(pages => pages.text())
.then(pages => pages.split('\n') .then(pages => pages.split('\n')
.filter(line => line) .filter(line => line)

View File

@ -1,9 +1,4 @@
document.body.dataset.editHost = window.location.protocol document.body.dataset.editUrl = '/edit/' + file.replace('.md', '')
+ '//edit.'
+ window.location.host
document.body.dataset.editUrl = document.body.dataset.editHost
+ '/'
+ file.replace('.md', '')
const topSection = window.location.pathname.split('/')[1] const topSection = window.location.pathname.split('/')[1]
if (topSection) document.body.classList.add(topSection) if (topSection) document.body.classList.add(topSection)

View File

@ -8,7 +8,7 @@
</button> </button>
{{ else if .Parent.Parent.IsHome }} {{ else if .Parent.Parent.IsHome }}
<button id="delete" <button id="delete"
class="br-pill f6 link dim br3 ph3 pv2 mb2 dib white bg-dark-gray pointer author-only" class="br-pill f6 link dim br3 ph3 pv2 mb2 dib white bg-dark-gray pointer"
data-confirm="{{ T (print .Section ".delete") }}?"> data-confirm="{{ T (print .Section ".delete") }}?">
{{ T (print .Section ".delete") }} {{ T (print .Section ".delete") }}
</button> </button>