"""Trusted shared site shell for the four visual theme designs and installed themes. Client-side search/filter works without a server after static export. """ from html import escape as e import json from pathlib import Path from . import db ASSETS=Path(__file__).resolve().parent/'static' def shell(html,site,page,records,nav): theme=site.get('theme','corporate') label=lambda key: e(str(key or ''),quote=True) links=[] if not nav: nav=[{'title':'首页','route':'/'},{'title':'产品中心','route':'/product/'},{'title':'品牌','route':'/brand/'}, {'title':'新闻资讯','route':'/post/'},{'title':'成功案例','route':'/case/'},{'title':'关于我们','route':'/about/'},{'title':'联系我们','route':'/contact/'}] seen=set() for n in nav[:25]: route=n.get('route','/') if route in seen:continue seen.add(route) links.append(f'{label(n.get("title"))}') # Themes can vary greatly in typography, but share an accessible responsive site shell. name=label(site['name']); tag=label(site.get('tagline','')) panels=''.join(f'{label(x["title"])}{label(x["summary"][:86])}' for x in records if x.get('type') in ('brand','service') and x.get('status')=='published')[:12000] header=f'''
合作咨询 ↗
{('
'+panels+'
') if panels else ''}
''' foot=f'''

{name}

{tag}

快速导航

{''.join(links[:6])}

联系我们

{label(site.get('email') or '请在管理后台填写联系邮箱')}

提交咨询 →
© {name}GLOBAL SOURCING · GLOBAL DELIVERY
''' # Every generated landing/detail page needs exactly one visible page heading. # Blueprints for information pages start with h2 blocks by default. if page.get('route') != '/' and '
' in html and '

EXPLORE / {label(page.get("type","PAGE")).upper()}

{label(page.get("title", ""))}

{label(page.get("summary", ""))}
' html=html.replace('
',intro+'
',1) html=html.replace('',''+header,1) html=html.replace('',foot+'',1) html=html.replace('','',1) return html def write_assets(dist,records): from shutil import copy2 copy2(ASSETS/'factory.css',dist/'assets'/'factory.css') copy2(ASSETS/'site-runtime.js',dist/'assets'/'site-runtime.js') search=[{'title':r['title'],'url':r['route'],'summary':(r.get('summary') or '')[:360], 'type':r['type'], 'brand':str((json.loads(r.get('meta_json') or '{}').get('fields') or {}).get('brand',''))} for r in records if r.get('route') and r['route']!='/'] (dist/'search-index.json').write_text(json.dumps(search,ensure_ascii=False),encoding='utf-8') def search_page(site): from html import escape return f'''站内搜索 - {escape(site['name'])}
← 返回首页

搜索网站内容

'''