PageSourceSearch

https://sinwang20.github.io/assets/js/blog.js

js sinwang20.github.io collected 2026-10-03 09:57:24 UTC 9,488 bytes, 251 lines download raw bytes

1(function () {
2  "use strict";
3
4  function slugify(text) {
5    return text.toLowerCase().trim()
6      .replace(/[^\w\s-]/g, "")
7      .replace(/\s+/g, "-");
8  }
9
10  function buildTableOfContents() {
11    var article = document.querySelector(".blog-content");
12    var list = document.getElementById("blog-toc-list");
13    if (!list) return;
14    if (!article) {
15      list.parentNode.style.display = "none";
16      return;
17    }
18
19    var headings = article.querySelectorAll("h2");
20    if (!headings.length) {
21      list.parentNode.style.display = "none";
22      return;
23    }
24
25    Array.prototype.forEach.call(headings, function (heading) {
26      if (!heading.id) heading.id = slugify(heading.textContent);
27      var item = document.createElement("li");
28      var link = document.createElement("a");
29      link.href = "#" + heading.id;
30      link.textContent = heading.textContent;
31      item.appendChild(link);
32      list.appendChild(item);
33    });
34  }
35
36  function markImageCaptions() {
37    var article = document.querySelector(".blog-content");
38    if (!article) return;
39
40    Array.prototype.forEach.call(article.querySelectorAll("blockquote"), function (caption) {
41      var previous = caption.previousElementSibling;
42      if (previous && previous.querySelector && previous.querySelector("img")) {
43        var figure = document.createElement("figure");
44        figure.className = "blog-figure";
45        previous.parentNode.insertBefore(figure, previous);
46        figure.appendChild(previous);
47        figure.appendChild(caption);
48        caption.classList.add("image-caption");
49      }
50    });
51  }
52
53  function wrapTables() {
54    var article = document.querySelector(".blog-content");
55    if (!article) return;
56
57    Array.prototype.forEach.call(article.querySelectorAll("table"), function (table) {
58      if (table.parentElement && table.parentElement.classList.contains("blog-table-wrap")) return;
59      var wrapper = document.createElement("div");
60      wrapper.className = "blog-table-wrap";
61      table.parentNode.insertBefore(wrapper, table);
62      wrapper.appendChild(table);
63    });
64  }
65
66  function linkInlineCitations() {
67    var article = document.querySelector(".blog-content");
68    if (!article) return;
69
70    var citations = [
71      ["One-Shot Imitation Learning", "https://arxiv.org/abs/1703.07326"],
72      ["One-Shot Imitation Learning,OSI", "https://arxiv.org/abs/1703.07326"],
73      ["OSI", "https://arxiv.org/abs/1802.01557"],
74      ["Action Tokenizer Matters", "https://arxiv.org/abs/2503.01206"],
75      ["BPP", "https://arxiv.org/abs/2606.30457"],
76      ["Behavior Prompting Policy", "https://arxiv.org/abs/2606.30457"],
77      ["SynthICL", "https://arxiv.org/abs/2606.08154"],
78      ["KAT", "https://arxiv.org/abs/2403.19578"],
79      ["ICRT", "https://arxiv.org/abs/2408.15980"],
80      ["BPP", "https://arxiv.org/abs/2606.30457"],
81      ["Instant Policy", "https://arxiv.org/abs/2411.12633"],
82      ["StellaVLA", "https://arxiv.org/abs/2608.11671"],
83      ["Vid2Robot", "https://arxiv.org/abs/2403.12943"],
84      ["MimicDroid", "https://arxiv.org/abs/2509.09769"],
85      ["Point Policy", "https://arxiv.org/abs/2502.20391"],
86      ["Qwen-RobotManip", "https://arxiv.org/abs/2606.17846"],
87      ["GEN-1.5", "https://generalistai.com/blog/gen-1.5"],
88      ["MemoryVLA", "https://arxiv.org/abs/2508.19236"],
89      ["ContextVLA", "https://arxiv.org/abs/2510.04246"],
90      ["Gated Memory Policy", "https://arxiv.org/abs/2604.18933"],
91      ["RoboTTT", "https://arxiv.org/abs/2607.15275"],
92      ["VANE", "https://arxiv.org/abs/2608.09448"],
93      ["Reflective VLA", "https://arxiv.org/abs/2606.25215"],
94      ["VICX", "https://arxiv.org/abs/2606.12028"],
95      ["HumanEgo", "https://arxiv.org/abs/2605.24934"],
96      ["Gen2Act", "https://arxiv.org/abs/2409.16283"],
97      ["RICL", "https://arxiv.org/abs/2508.02062"],
98      ["ICWM", "https://arxiv.org/abs/2606.26025"],
99      ["MEM", "https://arxiv.org/abs/2603.03596"],
100      ["HiMe", "https://arxiv.org/abs/2607.03449"],
101      ["MemER", "https://arxiv.org/abs/2510.20328"],
102      ["pi0.7", "https://arxiv.org/abs/2604.15483"],
103      ["\u03c00.7", "https://arxiv.org/abs/2604.15483"]
104    ].sort(function (left, right) { return right[0].length - left[0].length; });
105
106    function normalizeUrl(url) {
107      return (url || "").replace(/^https?:\/\//, "").replace(/\/$/, "");
108    }
109
110    var referenceHeading = Array.prototype.slice.call(article.querySelectorAll("h2")).filter(function (heading) {
111      return /^(references|\u53c2\u8003\u6587\u732e)$/i.test(heading.textContent.trim());
112    })[0];
113    if (!referenceHeading) return;
114
115    var referenceItems = [];
116    var next = referenceHeading.nextElementSibling;
117    while (next && next.tagName.toLowerCase() !== "h2") {
118      if (next.tagName.toLowerCase() === "ul") {
119        next.classList.add("blog-references");
120        Array.prototype.forEach.call(next.children, function (item) {
121          if (item.tagName.toLowerCase() === "li") referenceItems.push(item);
122        });
123      }
124      next = next.nextElementSibling;
125    }
126    if (!referenceItems.length) return;
127
128    var referencesByUrl = {};
129    referenceItems.forEach(function (item, index) {
130      var number = index + 1;
131      var anchor = item.querySelector("a[href]");
132      var url = anchor ? normalizeUrl(anchor.getAttribute("href")) : "";
133      item.id = "reference-" + number;
134      item.classList.add("blog-reference-item");
135      if (url) referencesByUrl[url] = number;
136      if (!item.querySelector(".blog-reference-number")) {
137        var marker = document.createElement("span");
138        marker.className = "blog-reference-number";
139        marker.textContent = "[" + number + "]";
140        var markerTarget = item.firstElementChild && item.firstElementChild.tagName === "P" ?
141          item.firstElementChild : item;
142        markerTarget.insertBefore(marker, markerTarget.firstChild);
143      }
144    });
145
146    var lookup = {};
147    citations.forEach(function (item) {
148      var number = referencesByUrl[normalizeUrl(item[1])];
149      if (number) lookup[item[0]] = number;
150    });
151    var activeCitations = citations.filter(function (item) { return lookup[item[0]]; });
152    if (!activeCitations.length) return;
153
154    function normalizeRefKey(key) {
155      return key.toLowerCase().trim().replace(/[\s_-]+/g, "");
156    }
157
158    var refLookup = {};
159    activeCitations.forEach(function (item) {
160      refLookup[normalizeRefKey(item[0])] = lookup[item[0]];
161    });
162
163    // Citations are opt-in: only an explicit \\ref{...} in the Markdown is linked.
164    var pattern = /\\ref\{[^}]+\}/g;
165    var walker = document.createTreeWalker(article, NodeFilter.SHOW_TEXT);
166    var nodes = [];
167    var node;
168
169    while ((node = walker.nextNode())) {
170      var parent = node.parentElement;
171      var excluded = false;
172      while (parent && parent !== article) {
173        if (["A", "CODE", "PRE", "H1", "H2", "H3"].indexOf(parent.tagName) !== -1 ||
174            parent.classList.contains("blog-reference-item")) {
175          excluded = true;
176          break;
177        }
178        parent = parent.parentElement;
179      }
180      if (!excluded && pattern.test(node.nodeValue)) {
181        nodes.push(node);
182      }
183      pattern.lastIndex = 0;
184    }
185
186    nodes.forEach(function (textNode) {
187      var text = textNode.nodeValue;
188      var fragment = document.createDocumentFragment();
189      var cursor = 0;
190      var match;
191      pattern.lastIndex = 0;
192
193      while ((match = pattern.exec(text))) {
194        fragment.appendChild(document.createTextNode(text.slice(cursor, match.index)));
195        var link = document.createElement("a");
196        var explicitKey = match[0];
197        var number = refLookup[normalizeRefKey(explicitKey.slice(5, -1))];
198        if (!number) {
199          fragment.appendChild(document.createTextNode(match[0]));
200          cursor = match.index + match[0].length;
201          continue;
202        }
203        link.className = "blog-citation-link";
204        link.href = "#reference-" + number;
205        link.title = explicitKey;
206        link.setAttribute("aria-label", "Reference " + number + ": " + explicitKey);
207        link.textContent = "[" + number + "]";
208        fragment.appendChild(link);
209        cursor = match.index + match[0].length;
210      }
211      fragment.appendChild(document.createTextNode(text.slice(cursor)));
212      textNode.parentNode.replaceChild(fragment, textNode);
213    });
214  }
215
216  function setupCitationCopy() {
217    var button = document.querySelector("[data-copy-citation]");
218    var code = document.querySelector(".blog-content pre code.language-bibtex") ||
219      document.querySelector(".blog-content pre code");
220    if (!button || !code) return;
221
222    button.addEventListener("click", function () {
223      var text = code.textContent;
224      var done = function () {
225        var original = button.textContent;
226        button.textContent = "Copied";
227        window.setTimeout(function () { button.textContent = original; }, 1400);
228      };
229
230      if (navigator.clipboard && navigator.clipboard.writeText) {
231        navigator.clipboard.writeText(text).then(done);
232      } else {
233        var area = document.createElement("textarea");
234        area.value = text;
235        document.body.appendChild(area);
236        area.select();
237        document.execCommand("copy");
238        area.remove();
239        done();
240      }
241    });
242  }
243
244  document.addEventListener("DOMContentLoaded", function () {
245    buildTableOfContents();
246    markImageCaptions();
247    wrapTables();
248    linkInlineCitations();
249    setupCitationCopy();
250  });
251}());

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.