Source: site.view [edit]
Function name: firstNameDescription
Arguments: name
Description:
Page type: webl
Render function:  
Module: global

Page source:

var cleanupMarkup = fun(s)
   s = Wub_ReplaceAll(s, "'", "");
   s = Wub_ReplaceAll(s, """, `"`);
   s = Wub_ReplaceAll(s, "&lt;", "<");
   s = Wub_ReplaceAll(s, "&gt;", ">");
   return s
end;

var cleanupLastLine = fun(s)
   var lines = Str_Split(s, "\n");
   var i = 0;
   if Size(lines) > 1 then
      s = "";
      while i < Size(lines) do
        if (Str_IndexOf("refer to", lines[i]) >= 0) then
           s = s + ""
        else 
           s = s + lines[i] + "\n\n";
        end;
        i = i + 1
      end;
   end;   
   // return lines[0];
   return s
end;
  
var cleanupRefs = fun(s)
   var res = "";
   var i = Str_IndexOf("<ref",s);
   while i != -1 do
      res = res + Select(s, 0, i);
      s = Select(s, i+Size("<ref"), Size(s));
      i = Str_IndexOf("</ref>", s);
      var j = Str_IndexOf("/>", s);
      var sz = Size("</ref>");
      if i == -1 then
         i = j;
         sz = Size("/>")
      end;
      if j < i and j >= 0 then
         i = j;
         sz = Size("/>");
      end;
      if i != -1 then
         // var txt = Select(s, 0, i);
         s = Select(s, i+sz, Size(s));
      end;
      i = Str_IndexOf("<ref",s);
   end;
   res = res + s;
   return res;
end;
  
  
var cleanupLinks = fun(s)
   var res = "";
   var i = Str_IndexOf("[[",s);
   while i != -1 do
      res = res + Select(s, 0, i);
      s = Select(s, i+2, Size(s));
      i = Str_IndexOf("]]", s);
      if i != -1 then
         var txt = Select(s, 0, i);
         s = Select(s, i+2, Size(s));
         var terms = Str_Split(txt, "|");
         if Size(terms) > 0 then
            txt = terms[Size(terms)-1]
         end;
         res = res + txt;
      end;
      i = Str_IndexOf("[[",s);
   end;
   res = res + s;
   return res;
end;

var cleanupBraces = fun(s)
   var res = "";
   var inBrace = 0;
   while s != "" do
     if Str_StartsWith(s, "{{") then
        inBrace = inBrace + 1;
        s = Select(s, 1, Size(s))
     elsif Str_StartsWith(s, "}}") then
        inBrace = inBrace - 1;
        s = Select(s, 1, Size(s))
     elsif inBrace == 0 then
          res = res + Select(s, 0, 1)
     end;
     s = Select(s, 1, Size(s))
   end;
   return res
end;

var cleanup = fun(res)
   res = cleanupBraces(res);
   res = cleanupLinks(res);
   res = cleanupMarkup(res);
   res = cleanupRefs(res);
   res = cleanupLastLine(res);

   res = Wub_ReplaceAll(res, "*", "");
   res = Wub_ReplaceAll(res, "<!--", "");
   res = Wub_ReplaceAll(res, "-->", "");
   res = Wub_ReplaceAll(res, ">", "");
   return res;
end;

var P = GetURL("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=revisions&rvprop=content&rvsection=0&titles=" + name + "%20(given%20name)");

var s = Markup(P);
var redirect = "#REDIRECT [[";
var i = Str_IndexOf(redirect, s);
if i == -1 then
   redirect = "#REDIRECT[[";
   i = Str_IndexOf(redirect, s);
end;
if i == -1 then
   redirect = "#redirect[[";
   i = Str_IndexOf(redirect, s);
end;
if i == -1 then
   redirect = "#redirect[[";
   i = Str_IndexOf(redirect, s);
end;   
if i > 0 then
   s = Select(s, i + Size(redirect), Size(s));
   i = Str_IndexOf("]]", s);
   s = Select(s, 0, i);
   s = Wub_ReplaceAll(s, " ", "%20");
   P = GetURL("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=revisions&rvprop=content&rvsection=0&titles=" + s);
   var s = Markup(P);
end;
  
if Str_IndexOf("revisions", s) == -1 then
   P = GetURL("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=revisions&rvprop=content&rvsection=0&titles=" + name);
   var s = Markup(P);
end;

s = ExpandCharEntities(P, s);

var res = "";
var Revs = Elem(P, "revisions");
if Size(Revs) > 0 then
   res = Text(Revs[0]);
   if Size(res) > 30 then
      res = Select(res, 22, Size(res))
   end;
end;
if Str_IndexOf("#redirect", Str_ToLowerCase(res)) >= 0 then
   res = ""
end;

res = cleanup(res);
res;