This page was created by volunteers like you!
Help us make it even better. To learn more about contributing to MEpedia, click here.
Join the movement
Visit #MEAction to find support or take action. Donate today to help us improve and expand this project.
Congratulations!
MEpedia has got over 30 million views as of August 2022!

Module talk:Citation/CS1

From MEpedia, a crowd-sourced encyclopedia of ME and CFS science and history

Code to try out -- notjusttired[edit source | reply | new]

Collected Lua code snippets for possibly creating automatic author links

  • grab first word of name, removing . or comma, as taken from Module:Citation/CS1 check for spaces in url
local function normalize_name(the_str)
--replace curly apostrophe or wrong hyphen symbol with correct ones for links
result = false

if not (the_str:match("(%A+)") == nil) then
 if not (the_str == "") then
  --there's some non-letters
  the_str = the_str:gsub("’","'") 
  the_str = the_str:gsub("%‑","-") 
  the_str = the_str:gsub("%‒","-") 
  the_str = the_str:gsub("%–","-")
  the_str = the_str:gsub("%‐","-")
  result = the_str
 end
end
return result; 
end

local function first_name(the_str)
-- trim comma, full stop, semicolon 
--allowed punctuation: dash/hyphen (em dash) and straight apostrophe
result = false 

--find first word according to space 
if not (the_str == nil) then
  the_str = the_str:match("^(%S+)") 
end 

--strip trailing punctuation 
the_str = the_str:gsub("%.","") 
the_str = the_str:gsub("%,", "") 
the_str = the_str:gsub("%;", "")

--replace curly apostrophe or wrong hyphen symbol with correct ones for links 
the_str = normalize_name(the_str)

if the_str == '' then 
--if empty return false
   result = false 
else 
   result = the_str 
end 
return result; 
end

  • Check if string empty or spaces exist in it by creating local function in module - this will ignore any authors with several last names
local function check_authorname( name_str)
result = true
    if (name_str == nil or name_str == '') then
-- value must not be empty
      result = false
    end
    if nil == name_str:match ("^%S+$") then										-- value must not contain spaces
      result = false
    end
    return result;
end

  • If author last name exists and first name exist, concatenate for author-link (author2-link etc) (first name may be an initial, which we can sort with redirects)
    • and if author last name exists and first name does not exist, use last name for author-link (author2-link etc)
local function make_authorlink (first_str, last_str)
first_str = first_name(first_str)
last_str = normalize_name(last_str)
result = ''
  if check_authorname(last_str) == true then
   if check_authorname(first_str) == true then
     result = first_str..' '..last_str
   else
--last name without first name is also valid eg for organizations
     result = last_str
    end
  end
return result;
end

    • but only if a page with that name already exists???

  • loop through authors 1 to 19, until no more authors exist

Link to other modules[edit source | reply | new]

  • use require, invoke eg getauthorlink = require ('Module:Citation/CS1/Getauthorlink');
  • call functions with modulename.functionname(params) eg getauthorlink.make_authorlink(first_str, last_str)
  • passing parameters to / from new module

Testing[edit source | reply | new]

code here]


Lua code for possible date fixes[edit source | reply | new]

2009-04 for instance - may be fixed by future citoid release

notjusttired