Files
mama-box/tools/share-card/build.js

54 lines
6.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 生成转发图清单:百问专题 / 计算器 / 测试 / 广场笔记 / 广场话题
const fs = require('fs'), R = '/work/mama-box/';
global.window = {};
const ev = f => eval(fs.readFileSync(R + f, 'utf8'));
ev('guangchang/data.js'); ev('guangchang/topics.js'); ev('guangchang/ceshi/meta.js');
const hot = require(R + 'assets/data/qa/hot.json');
const src = fs.readFileSync(R + 'js/app.js', 'utf8');
const kwSrc = src.slice(src.indexOf('const QA_KW = {') + 14, src.indexOf('};', src.indexOf('const QA_KW = {')) + 1);
const QA_KW = eval('(' + kwSrc.replace(/\/\*[\s\S]*?\*\//g, '') + ')');
const KW2 = { ceshi: '哪种妈妈', wen: '妊娠纹', zhichang: '复工维权', shaicha: '唐筛无创', kafei: '咖啡奶茶', ranfa: '染发烫发', taidong: '初次胎动',
fenmian: '顺产剖宫', daichanbao: '待产包', shimian: '孕期失眠', tongfang: '孕期同房', zhunbaba: '准爸爸', pinxue: '孕期贫血', gaoxueya: '血压高',
baidai: '白带增多', taijiao: '胎教', yuezi: '坐月子', hcg: 'HCG孕酮', yuchanqi: '预产期', tuyy: '孕吐营养', futong: '肚子隐痛', jikou: '孕早期忌口',
xianhuai: '显怀', bugai: '补钙补铁', weikou: '控制体重', zhangban: '长斑变黑', touyun: '头晕心慌', yunfu: '孕妇装', gongjing: '宫颈短', fansuan: '烧心反酸',
chigu: '耻骨痛', jiagong: '假性宫缩', taidongshao: '胎动变少', yangshui: '羊水', wutong: '无痛分娩', poshui: '破水', jianhongsheng: '见红待产', ruyuan: '入院证件',
kainai: '开奶', chusheng: '出生打针', duiyou: '队友类型', yali: '孕期压力', yinshi: '饮食打分', zhunbei: '准备几成', jisuan: '孕期计算器', 'yuchanqi-js': '预产期' };
const TAGC = { 身体: '#EE6A8C', 准备: '#6C78E6', 产检: '#3C8BE6', 宝宝: '#FF8F3F', 生活: '#2FAE84', 营养: '#4BAE5E', 职场: '#5B6FD8', 花钱: '#F0962A', 心情: '#E66B9A', 趣味: '#9A7FE0', 补剂: '#3C9BD8', 专题: '#22A3A0' };
// 11-04 新增 10 个计算器:[大字, 标题, 主色]
const NEWC = { 'yunzhou-js': ['孕几周了', '今天孕几周几天、孕几个月、宝宝像什么', '#E2668E'], 'chanjian-js': ['产检时间表', '每次产检哪天去、查什么,一张表排清楚', '#2F86C9'],
'zengzhong-js': ['胖多少合适', '按孕前身高体重,算孕期增重的合适范围', '#2E9C6A'], 'jintie-js': ['生育津贴', '产假期间能领多少钱?按缴费工资算一算', '#E0812A'],
'butie-js': ['育儿补贴', '每孩每年 3600 元领到 3 岁,你家能领多少', '#E25C5C'], 'geshui-js': ['个税省多少', '有 3 岁以下宝宝,每月多扣 2000,一年少交多少税', '#6C5BD6'],
'yuezi-js': ['月子花费', '月子中心、请月嫂、在家坐,各要花多少钱', '#C9658F'], 'shengao-js': ['宝宝多高', '按爸妈身高,推算宝宝长大后大概多高', '#1F9BA8'],
'xuexing-js': ['宝宝血型', '爸妈血型配一配,宝宝可能是什么血型', '#D9475A'], 'shouxu-js': ['出生后手续', '出生证、上户口、医保、社保卡,每件事截止哪天', '#4E7FD8'] };
const QUIZ_TOPIC = { ceshi: 1, duiyou: 1, yali: 1, yinshi: 1, zhunbei: 1 };
const CALC = { huafei: 1, jisuan: 1, 'yuchanqi-js': 1 };
const out = [];
const tt = d => (fs.readFileSync(R + 'topic/' + d + '/index.html', 'utf8').match(/<title>([^<]*)/) || [])[1] || '';
const dirs = fs.readdirSync(R + 'topic').filter(d => fs.existsSync(R + 'topic/' + d + '/index.html'));
dirs.forEach(d => {
if (NEWC[d]) { out.push({ k: 't/' + d, type: 'text', mod: '孕期计算器', c: NEWC[d][2], big: NEWC[d][0], title: NEWC[d][1], cta: '马上算一算', ic: 'calc' }); return; }
const h = hot.find(x => x.href === 'topic/' + d + '/');
const q = h ? h.q : tt(d).replace(/^测一测:/, '').replace(/\s*[·||].*$/, '');
const kw = (h && QA_KW[h.q]) || KW2[d];
if (!kw) throw new Error('no kw ' + d);
let mod = '孕期百问', c = TAGC[h ? h.tag : '趣味'] || '#22A3A0', cta = '点开看答案';
if (QUIZ_TOPIC[d]) { mod = '测一测'; c = '#9A7FE0'; cta = '点开测一测'; }
if (CALC[d]) { mod = '孕期计算器'; c = '#F57C4C'; cta = '马上算一算'; }
if (d === 'jisuan') { out.push({ k: 't/' + d, type: 'text', mod, c, big: '孕期计算器', title: '生娃花费、预产期、产假天数,一算就知道', cta, ic: 'calc' }); return; }
if (d === 'yuchanqi-js') { out.push({ k: 't/' + d, type: 'text', mod, c, big: '预产期', title: '宝宝哪天到?还有几天见面', cta, ic: 'calc' }); return; }
out.push({ k: 't/' + d, type: 'text', mod, c, big: kw, title: q, cta, ic: CALC[d] ? 'calc' : QUIZ_TOPIC[d] ? 'quiz' : (h ? h.tag : '专题') });
});
const GC = { quiz: '#FF8A65', psy: '#9A7FE0', game: '#3FAE7A', shop: '#4E8DE6' }, GN = { quiz: '常识小测', psy: '趣味心理', game: '趣味闯关', shop: '好物配置' };
window.GC_TESTS_META.forEach(x => out.push({ k: 'c/' + x.id, type: 'text', mod: '测一测 · ' + GN[x.group], c: GC[x.group], big: window.GC_SHORT[x.id] || '', title: x.title.replace(/^测一测|/, ''), cta: '点开测一测', ic: 'test:' + x.id, sub: x.n + ' 道题 · 测完看结果' }));
const T = window.GC_TOPICS, D = window.GC_DATA;
T.forEach(t => {
out.push({ k: 'g/t-' + t.id, type: 'photo', mod: '孕妈广场 · 话题', c: t.ink || '#F4593C', bg: t.c, big: '#' + t.name + '#', title: (D[t.id] && D[t.id].desc) || '', cta: '进来聊聊', ph: t.ph ? R + t.ph : '' });
((D[t.id] && D[t.id].notes) || []).forEach((n, i) => out.push({ k: 'g/' + t.id + '-' + (i + 1), type: 'photo', mod: '孕妈广场', c: t.ink || '#F4593C', bg: t.c, big: n.cover || n.title, sub: n.coverSub || '', title: n.title, cta: '看看她怎么说', ph: n.photo ? R + 'guangchang/' + n.photo : '' }));
});
out.push({ k: 'g/home', type: 'text', mod: '孕妈广场', c: '#F4593C', big: '孕妈广场', title: '孕期的那些事,听听过来人怎么说', cta: '进来看看', ic: 'plaza' });
out.push({ k: 'g/ceshi', type: 'text', mod: '测一测', c: '#8D6BFF', big: '趣味小测试', title: '30 个孕育小测试,1 分钟测出你是哪种孕妈', cta: '点开测一测', ic: 'quiz' });
const strip = v => typeof v === 'string' ? v.replace(/[\p{Extended_Pictographic}\uFE0F\u200D]/gu, '').replace(/\s{2,}/g, ' ').trim() : v;
out.forEach(x => ['big', 'title', 'sub'].forEach(k => { x[k] = strip(x[k]); }));
fs.writeFileSync('/work/mama-box/tools/share-card/manifest.json', JSON.stringify(out, null, 1));
console.log(out.length, out.filter(x => x.type === 'photo' && !x.ph).length);