tag.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. const models = require('../models');
  2. const translate = require('../config/translate');
  3. const meta = require('../config/meta');
  4. let tags = [
  5. "animal",
  6. "scenery",
  7. "people",
  8. "life",
  9. "plant",
  10. "girl",
  11. "flower",
  12. "fantasy",
  13. "data_good",
  14. "mandala",
  15. "food",
  16. "special_date",
  17. "nature",
  18. "cat",
  19. "landscape",
  20. "dog",
  21. "countryside",
  22. "forest",
  23. "ban",
  24. "flowers",
  25. "bird",
  26. "river",
  27. "mountains",
  28. "snow",
  29. "recommend",
  30. "winter",
  31. "house",
  32. "village",
  33. "heart",
  34. "Christmas",
  35. "garden",
  36. "butterfly",
  37. "fashion",
  38. "summer",
  39. "farm",
  40. "boy",
  41. "place",
  42. "sea",
  43. "culture",
  44. "car",
  45. "horse",
  46. "lake",
  47. "autumn",
  48. "tree",
  49. "building",
  50. "wild",
  51. "woman",
  52. "room",
  53. "park",
  54. "ocean",
  55. "meadow",
  56. "rabbit",
  57. "family",
  58. "patterns",
  59. "home",
  60. "mountain",
  61. "halloween",
  62. "bridge",
  63. "friends",
  64. "city",
  65. "baby",
  66. "sunset",
  67. "simple",
  68. "boat",
  69. "window",
  70. "plants",
  71. "man",
  72. "trees",
  73. "fruit",
  74. "rose",
  75. "vacation",
  76. "evening",
  77. "castle",
  78. "snowman",
  79. "street",
  80. "tiger",
  81. "grass",
  82. "lady",
  83. "child",
  84. "vintage",
  85. "holiday",
  86. "pasture",
  87. "deer",
  88. "sweet",
  89. "night",
  90. "beach",
  91. "travel",
  92. "dress",
  93. "fish",
  94. "couple",
  95. "view",
  96. "fairy",
  97. "harvest",
  98. "yard",
  99. "sky",
  100. "toys",
  101. "wildflowers",
  102. "love",
  103. "pumpkin",
  104. "water",
  105. "transportation",
  106. "birds",
  107. "rocks",
  108. "famous",
  109. "downtown",
  110. "ice",
  111. "bear",
  112. "spring",
  113. "road",
  114. "wolf",
  115. "unicorn",
  116. "lion",
  117. "stone",
  118. "magic",
  119. "cake",
  120. "book",
  121. "furniture",
  122. "children",
  123. "fox",
  124. "cartoon",
  125. "duck",
  126. "owl",
  127. "squirrel",
  128. "sport",
  129. "angel",
  130. "cub",
  131. "decorations",
  132. "pond",
  133. "sheep",
  134. "fence",
  135. "interior",
  136. "coastline",
  137. "beauty",
  138. "chicken",
  139. "train",
  140. "mermaid",
  141. "history",
  142. "moon",
  143. "picnic",
  144. // "bedroom",
  145. // "blooming",
  146. // "sunflower",
  147. // "mystery",
  148. // "lovers",
  149. // "stairs",
  150. // "walk",
  151. // "jungle",
  152. // "livingroom",
  153. // "thanksgiving",
  154. // "kingdom",
  155. // "mother and daughter",
  156. // "domestic",
  157. // "mother",
  158. // "lotus",
  159. // "dragon",
  160. // "panda",
  161. // "pet",
  162. // "cottage",
  163. // "tea",
  164. // "coast",
  165. ]
  166. function getRandomDarkColor() {
  167. // 生成 0 到 127 之间的随机整数,因为较深的颜色分量值较低
  168. const r = Math.floor(Math.random() * 222);
  169. const g = Math.floor(Math.random() * 222);
  170. const b = Math.floor(Math.random() * 222);
  171. // 将 RGB 值转换为十六进制字符串
  172. const toHex = (num) => {
  173. const hex = num.toString(16);
  174. return hex.length === 1 ? `0${hex}` : hex;
  175. };
  176. // 返回 RGB 十六进制颜色字符串
  177. return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
  178. }
  179. tags = tags.map(e => { return { tag: e, color: getRandomDarkColor() } });
  180. let tagSeoMap = {};
  181. async function getTagSeoTitle(tag, lang) {
  182. let item = tagSeoMap[tag];
  183. if (!item) {
  184. let doc = await models.TagSeo.findOne({ tag }).lean();
  185. if (doc) {
  186. try {
  187. doc.seoTitle = JSON.parse(doc.seoTitle);
  188. doc.seoDescription = JSON.parse(doc.seoDescription);
  189. tagSeoMap[tag] = doc;
  190. item = doc;
  191. } catch (e) {
  192. console.error(e.message);
  193. }
  194. }
  195. }
  196. if (item) {
  197. return tagSeoMap[tag].seoTitle[lang];
  198. } else {
  199. return `${tag} coloring pages | ${translate.printableColoringPage[lang]}`;
  200. }
  201. }
  202. async function getTagSeoDescription(tag, lang) {
  203. let item = tagSeoMap[tag];
  204. if (!item) {
  205. let doc = await models.TagSeo.findOne({ tag }).lean();
  206. if (doc) {
  207. try {
  208. doc.seoTitle = JSON.parse(doc.seoTitle);
  209. doc.seoDescription = JSON.parse(doc.seoDescription);
  210. tagSeoMap[tag] = doc;
  211. item = doc;
  212. } catch (e) {
  213. console.error(e.message);
  214. }
  215. }
  216. }
  217. if (item) {
  218. return tagSeoMap[tag].seoDescription[lang];
  219. } else {
  220. return meta.tagDescription[lang];
  221. }
  222. }
  223. module.exports = { tags, getTagSeoTitle, getTagSeoDescription };