| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- const models = require('../models');
- const translate = require('../config/translate');
- const meta = require('../config/meta');
- let tags = [
- "animal",
- "scenery",
- "people",
- "life",
- "plant",
- "girl",
- "flower",
- "fantasy",
- "data_good",
- "mandala",
- "food",
- "special_date",
- "nature",
- "cat",
- "landscape",
- "dog",
- "countryside",
- "forest",
- "ban",
- "flowers",
- "bird",
- "river",
- "mountains",
- "snow",
- "recommend",
- "winter",
- "house",
- "village",
- "heart",
- "Christmas",
- "garden",
- "butterfly",
- "fashion",
- "summer",
- "farm",
- "boy",
- "place",
- "sea",
- "culture",
- "car",
- "horse",
- "lake",
- "autumn",
- "tree",
- "building",
- "wild",
- "woman",
- "room",
- "park",
- "ocean",
- "meadow",
- "rabbit",
- "family",
- "patterns",
- "home",
- "mountain",
- "halloween",
- "bridge",
- "friends",
- "city",
- "baby",
- "sunset",
- "simple",
- "boat",
- "window",
- "plants",
- "man",
- "trees",
- "fruit",
- "rose",
- "vacation",
- "evening",
- "castle",
- "snowman",
- "street",
- "tiger",
- "grass",
- "lady",
- "child",
- "vintage",
- "holiday",
- "pasture",
- "deer",
- "sweet",
- "night",
- "beach",
- "travel",
- "dress",
- "fish",
- "couple",
- "view",
- "fairy",
- "harvest",
- "yard",
- "sky",
- "toys",
- "wildflowers",
- "love",
- "pumpkin",
- "water",
- "transportation",
- "birds",
- "rocks",
- "famous",
- "downtown",
- "ice",
- "bear",
- "spring",
- "road",
- "wolf",
- "unicorn",
- "lion",
- "stone",
- "magic",
- "cake",
- "book",
- "furniture",
- "children",
- "fox",
- "cartoon",
- "duck",
- "owl",
- "squirrel",
- "sport",
- "angel",
- "cub",
- "decorations",
- "pond",
- "sheep",
- "fence",
- "interior",
- "coastline",
- "beauty",
- "chicken",
- "train",
- "mermaid",
- "history",
- "moon",
- "picnic",
- "bedroom",
- "blooming",
- "sunflower",
- "mystery",
- "lovers",
- "stairs",
- "walk",
- "jungle",
- "livingroom",
- "thanksgiving",
- "kingdom",
- "mother and daughter",
- "domestic",
- "mother",
- "lotus",
- "dragon",
- "panda",
- "pet",
- "cottage",
- "tea",
- "coast",
- ]
- function getRandomDarkColor() {
- // 生成 0 到 127 之间的随机整数,因为较深的颜色分量值较低
- const r = Math.floor(Math.random() * 222);
- const g = Math.floor(Math.random() * 222);
- const b = Math.floor(Math.random() * 222);
- // 将 RGB 值转换为十六进制字符串
- const toHex = (num) => {
- const hex = num.toString(16);
- return hex.length === 1 ? `0${hex}` : hex;
- };
- // 返回 RGB 十六进制颜色字符串
- return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
- }
- tags = tags.map(e => { return { tag: e, color: getRandomDarkColor() } });
- let tagSeoMap = {};
- async function getTagSeoTitle(tag, lang) {
- let item = tagSeoMap[tag];
- if (!item) {
- let doc = await models.TagSeo.findOne({ tag }).lean();
- if (doc) {
- try {
- doc.seoTitle = JSON.parse(doc.seoTitle);
- doc.seoDescription = JSON.parse(doc.seoDescription);
- tagSeoMap[tag] = doc;
- item = doc;
- } catch (e) {
- console.error(e.message);
- }
- }
- }
- if (item) {
- return tagSeoMap[tag].seoTitle[lang];
- } else {
- return `${tag} coloring pages | ${translate.printableColoringPage[lang]}`;
- }
- }
- async function getTagSeoDescription(tag, lang) {
- let item = tagSeoMap[tag];
- if (!item) {
- let doc = await models.TagSeo.findOne({ tag }).lean();
- if (doc) {
- try {
- doc.seoTitle = JSON.parse(doc.seoTitle);
- doc.seoDescription = JSON.parse(doc.seoDescription);
- tagSeoMap[tag] = doc;
- item = doc;
- } catch (e) {
- console.error(e.message);
- }
- }
- }
- if (item) {
- return tagSeoMap[tag].seoDescription[lang];
- } else {
- return meta.tagDescription[lang];
- }
- }
- module.exports = { tags, getTagSeoTitle, getTagSeoDescription };
|