PageSourceSearch

https://learningpathway.in/meta.js

js learningpathway.in collected 2026-10-07 04:23:00 UTC 5,937 bytes, 184 lines download raw bytes

1  function generateSeoScehma(getPageListResponse){
2    const dayAbbreviations = {
3      Monday: "Mo",
4      Tuesday: "Tu",
5      Wednesday: "We",
6      Thursday: "Th",
7      Friday: "Fr",
8      Saturday: "Sa",
9      Sunday: "Su"
10  };
11  let openingHours=[];
12  if(getPageListResponse?.opngHrsStructData)
13  {
14    try {
15      const openingHoursArr = JSON.parse(getPageListResponse.opngHrsStructData) || [];
16      openingHours = openingHoursArr && openingHoursArr?.length > 0 && openingHoursArr.map(({ dayOfWeek, opens, closes }) =>{
17        const dayAbbr=dayAbbreviations[dayOfWeek];
18        if(!opens || !closes || opens==='undefined' || closes==='undefined')
19        {
20          return `${dayAbbr} closed`;
21        }
22        return `${dayAbbr} ${opens}-${closes}`;
23
24        
25      }
26        
27
28      );
29  } catch (error) {
30      console.error("Error parsing opngHrsStructData:", error);
31  }
32  
33  }
34  //console.log("addrTypeStrctData:::",getPageListResponse?.addrTypeStrctData)
35  const seoStrctDataType = getPageListResponse?.seoStrctDataType || "Default";
36  let schema = {};
37  if(seoStrctDataType.length > 0 && seoStrctDataType === "Custom"){
38    try {
39      schema = JSON.parse(getPageListResponse?.customSeoStrctData || "{}");
40    } catch (error) {
41      schema = {};
42    }
43  } else {
44     schema = {
45      "@context": "https://schema.org",
46      "@type": getPageListResponse?.typeStrctData||"LocalBusiness",
47      "name": getPageListResponse?.nameStrctData || "",
48      "url": window.origin,
49      "telephone": getPageListResponse?.tlphnStrctData || "",
50      "address": {
51        "@type": getPageListResponse?.addrTypeStrctData||"PostalAddress",
52        "streetAddress": getPageListResponse?.streetAddrStrctData || "",
53        "addressLocality": getPageListResponse?.addrLcltyStrctData || "",
54        "postalCode": getPageListResponse?.pstlCdeStrctData || "",
55        "addressCountry": getPageListResponse?.addrCuntyStrctData || ""
56      },
57      "openingHours":openingHours ,
58      "sameAs": getPageListResponse.sameAsStructData || ''
59    };
60  }  
61  return schema;
62  
63}
64// function insertSchemaIntoDOM  (schema) {
65//     //console.log("test :: schema 1:::",schema)
66//     const scriptTag = document.createElement("script");
67//     scriptTag.type = "application/ld+json";
68//     scriptTag.textContent = JSON.stringify(schema, null, 2);
69//     document.head.appendChild(scriptTag);
70//   };
71function insertSchemaIntoDOM(schema) {
72  let existing = document.querySelector("script[type='application/ld+json']");
73
74  if (existing) {
75    existing.textContent = JSON.stringify(schema, null, 2);
76  } else {
77    const scriptTag = document.createElement("script");
78    scriptTag.type = "application/ld+json";
79    scriptTag.textContent = JSON.stringify(schema, null, 2);
80    document.head.appendChild(scriptTag);
81  }
82}
83
84function runMetaUpdate  (getPageListResponse)  {
85  const metaAppTitle =
86    getPageListResponse?.appTitle ||
87    getPageListResponse?.appName ||
88    "Open Weaver Studio";
89
90  const description =
91    getPageListResponse?.appDescription || metaAppTitle;
92
93  const appKeywords =
94    getPageListResponse?.appKeywords || metaAppTitle;
95
96  const fbAppId = getPageListResponse?.fbAppId?.trim();
97
98  const studioCoverImage=getPageListResponse?.coverImage?.trim();
99
100  let studioIconImage =
101    getPageListResponse?.appFavicon || "/appln-favicon.png";
102
103  let studioImage =
104    getPageListResponse?.coverImage || studioIconImage;
105
106
107
108  const faviconType = studioIconImage.endsWith(".ico")
109    ? "image/x-icon"
110    : studioIconImage.endsWith(".png")
111    ? "image/png"
112    : studioIconImage.endsWith(".gif")
113    ? "image/gif"
114    : "image/png";
115
116  // Batch DOM updates (reduce reflow)
117  const fragment = document.createDocumentFragment();
118
119  const setMeta = (selector, attr, value, isProperty = false) => {
120    let tag = document.querySelector(selector);
121    if (!tag) {
122      tag = document.createElement("meta");
123      tag.setAttribute(isProperty ? "property" : "name", attr);
124      fragment.appendChild(tag);
125    }
126    tag.setAttribute("content", value);
127  };
128
129  // Only write page-level meta tags if React hasn't already set page-specific values
130  if (!window.__pageMetaTitleSet) {
131    setMeta("meta[property='og:title']", "og:title", metaAppTitle, true);
132    setMeta("meta[name='twitter:title']", "twitter:title", metaAppTitle);
133    document.title = metaAppTitle;
134  }
135  if (!window.__pageMetaDescriptionSet) {
136    setMeta("meta[property='og:description']", "og:description", description, true);
137    setMeta("meta[name='twitter:description']", "twitter:description", description);
138    setMeta("meta[name='description']", "description", description);
139  }
140  if (!window.__pageMetaKeywordsSet) {
141    setMeta("meta[name='keywords']", "keywords", appKeywords);
142  }
143  if(studioCoverImage)
144  {
145    setMeta("meta[property='og:image']", "og:image", studioCoverImage,true);
146  }
147  setMeta("meta[name='twitter:image']", "twitter:image", studioImage);
148  if (fbAppId) {
149    setMeta("meta[property='fb:app_id']", "fb:app_id", fbAppId, true);
150  }
151
152  // Append new tags once
153  document.head.appendChild(fragment);
154
155  // Favicon (outside fragment)
156  const setLink = (rel) => {
157    let link = document.querySelector(`link[rel='${rel}']`);
158    if (!link) {
159      link = document.createElement("link");
160      link.rel = rel;
161      document.head.appendChild(link);
162    }
163    link.href = studioIconImage;
164    link.type = faviconType;
165  };
166
167  setLink("icon");
168  setLink("shortcut icon");
169  setLink("apple-touch-icon");
170  //const schemaData = generateSeoScehma(getPageListResponse);
171  // Insert schema into DOM
172  //insertSchemaIntoDOM(schemaData);
173  if ("requestIdleCallback" in window) {
174  requestIdleCallback(() => {
175    const schemaData = generateSeoScehma(getPageListResponse);
176    insertSchemaIntoDOM(schemaData);
177  });
178} else {
179  setTimeout(() => {
180    const schemaData = generateSeoScehma(getPageListResponse);
181    insertSchemaIntoDOM(schemaData);
182  }, 0);
183}
184};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.