33 lines
2.0 KiB
Python
33 lines
2.0 KiB
Python
|
|
"""Deterministic demo, only writes to an explicitly isolated SITEFORGE_DATA_DIR."""
|
||
|
|
import json
|
||
|
|
import os
|
||
|
|
from pathlib import Path
|
||
|
|
if not os.getenv('SITEFORGE_DATA_DIR'):
|
||
|
|
raise SystemExit('Please set SITEFORGE_DATA_DIR to a disposable directory first')
|
||
|
|
import sys
|
||
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]))
|
||
|
|
from app import db, multilingual, builder, theme_store
|
||
|
|
from app.core import save_entry, uid
|
||
|
|
|
||
|
|
db.init()
|
||
|
|
theme_store.setup()
|
||
|
|
multilingual.setup()
|
||
|
|
records=[('zh-CN','中文官网','https://zh.demo.example.org','/about/','关于我们','全球服务网络'),
|
||
|
|
('en','Global Website','https://en.demo.example.org','/company/','About Our Company','Worldwide service network')]
|
||
|
|
ids={}; content={}
|
||
|
|
for locale,name,domain,about,title,body in records:
|
||
|
|
sid=uid(); ids[locale]=sid
|
||
|
|
db.insert('''INSERT INTO sites VALUES (?,?,?,?,?,?,?,?,?,?,?)''',
|
||
|
|
(sid,name,domain,'SiteForge P6 international demonstration','corporate','#2563eb','','new','{}',db.now(),db.now()))
|
||
|
|
home=save_entry(sid,{'type':'page','title':name,'route':'/','body':f'<p>{body}</p>'})
|
||
|
|
detail=save_entry(sid,{'type':'page','title':title,'route':about,'body':f'<p>{body}</p>'})
|
||
|
|
content[locale]={'home':home,'about':detail}
|
||
|
|
gid=uid();db.insert('INSERT INTO language_groups VALUES (?,?,?,?)',(gid,'HESU multilingual demo','en',db.now()))
|
||
|
|
for locale in ids:db.insert('INSERT INTO language_sites VALUES (?,?,?)',(gid,ids[locale],locale))
|
||
|
|
for key in ('home','about'):
|
||
|
|
unit=uid();db.insert('INSERT INTO translation_units VALUES (?,?,?,?)',(unit,gid,key,db.now()))
|
||
|
|
for locale in ids:db.insert('INSERT INTO translation_members VALUES (?,?,?,?)',(unit,ids[locale],content[locale][key],'approved'))
|
||
|
|
for locale,sid in ids.items():
|
||
|
|
report=builder.build(sid)
|
||
|
|
print(json.dumps({'locale':locale,'site_id':sid,'build':report['version'],'pages':report['pages'],'alternates':report['alternate_pages'],'errors':report['errors'],'warnings':report['warnings'][:3]},ensure_ascii=False))
|