texlive[52145] trunk: ctanbib (21sep19)
commits+karl at tug.org
commits+karl at tug.org
Sat Sep 21 23:52:54 CEST 2019
Revision: 52145
http://tug.org/svn/texlive?view=revision&revision=52145
Author: karl
Date: 2019-09-21 23:52:54 +0200 (Sat, 21 Sep 2019)
Log Message:
-----------
ctanbib (21sep19)
Modified Paths:
--------------
trunk/Build/source/texk/texlive/linked_scripts/ctanbib/ctanbib
trunk/Master/texmf-dist/doc/man/man1/ctanbib.man1.pdf
trunk/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.pdf
trunk/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.tex
trunk/Master/texmf-dist/scripts/ctanbib/ctanbib
Modified: trunk/Build/source/texk/texlive/linked_scripts/ctanbib/ctanbib
===================================================================
--- trunk/Build/source/texk/texlive/linked_scripts/ctanbib/ctanbib 2019-09-21 21:52:09 UTC (rev 52144)
+++ trunk/Build/source/texk/texlive/linked_scripts/ctanbib/ctanbib 2019-09-21 21:52:54 UTC (rev 52145)
@@ -27,7 +27,7 @@
]])
os.exit(1)
elseif arg[1]=="--version" or arg[1]=="-v" then
- print "ctanbib version v0.1c"
+ print "ctanbib version 0.1d"
os.exit(1)
elseif arg[1]=="--ctan" or arg[1]=="-c" then
table.remove(arg, 1)
@@ -35,7 +35,8 @@
end
local pkgname = arg[1]
-local url = "https://www.ctan.org/xml/pkg/" .. pkgname
+local url = "https://www.ctan.org/xml/2.0/pkg/" .. pkgname .. "?author-name=true"
+local authors_url = "https://ctan.org/xml/2.0/authors"
-- change that for different title scheme
local titleformat = "The %s package"
@@ -76,18 +77,52 @@
end)
end
+-- we need to use this method temporarily because of a bug in
+-- CTAN API
+local author_list
+local fetch_author_list = function()
+ if author_list then return author_list end
+ local authors = load_xml(authors_url)
+ author_list = {}
+ for _, author in ipairs(authors:query_selector("author")) do
+ -- save all authors under they ID
+ local id = author:get_attribute("id")
+ author_list[id] = author
+ end
+ return author_list
+end
+
+local process_author = function(author)
+ local current = {}
+ current[#current+1] = author:get_attribute("familyname")
+ current[#current+1] = author:get_attribute("givenname")
+ -- the author is an organization
+ if #current == 1 then
+ return "{" .. current[1] .. "}"
+ elseif #current > 1 then
+ return table.concat(current, ", ")
+ end
+ return nil -- no author
+end
+
+-- get the author name and surname
+local get_author = function(author)
+ local name = process_author(author)
+ if name then return name end
+ -- if the package XML doesn't contain author name,
+ -- we need to fetch the authors list from CTAN and find
+ -- it here
+ local author_list = fetch_author_list()
+ local id = author:get_attribute("id")
+ -- try to find the author id in list of authors
+ -- if everything fails, just return an empty group
+ return process_author(author_list[id]) or "{}"
+end
+
local get_authors = function(a)
local retrieved_authors = {}
for _, author in ipairs(a) do
- local current = {}
- current[#current+1] = author:get_attribute("familyname")
- current[#current+1] = author:get_attribute("givenname")
- -- the author is an organization
- if #current == 1 then
- table.insert(retrieved_authors, "{" .. current[1] .. "}")
- else
- table.insert(retrieved_authors, table.concat(current, ", "))
- end
+ table.insert(retrieved_authors, get_author(author))
end
return table.concat(retrieved_authors," and ")
end
Modified: trunk/Master/texmf-dist/doc/man/man1/ctanbib.man1.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.tex 2019-09-21 21:52:09 UTC (rev 52144)
+++ trunk/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.tex 2019-09-21 21:52:54 UTC (rev 52145)
@@ -99,6 +99,8 @@
\section{Changelog}
\begin{changelog}
+ \change{2019-09-21}{Try to find the author in full CTAN author list if the author cannot be found in the package info}
+ \change{2019-09-16}{Use the CTAN API 2.0 to fetch the package info}
\change{2019-05-04}{Version 0.1c released}
\change{2019-05-04}{Use the \texttt{curl} command to download the package info}
\change{2019-05-04}{Added information about the need to have the \texttt{curl} command installed}
Modified: trunk/Master/texmf-dist/scripts/ctanbib/ctanbib
===================================================================
--- trunk/Master/texmf-dist/scripts/ctanbib/ctanbib 2019-09-21 21:52:09 UTC (rev 52144)
+++ trunk/Master/texmf-dist/scripts/ctanbib/ctanbib 2019-09-21 21:52:54 UTC (rev 52145)
@@ -27,7 +27,7 @@
]])
os.exit(1)
elseif arg[1]=="--version" or arg[1]=="-v" then
- print "ctanbib version v0.1c"
+ print "ctanbib version 0.1d"
os.exit(1)
elseif arg[1]=="--ctan" or arg[1]=="-c" then
table.remove(arg, 1)
@@ -35,7 +35,8 @@
end
local pkgname = arg[1]
-local url = "https://www.ctan.org/xml/pkg/" .. pkgname
+local url = "https://www.ctan.org/xml/2.0/pkg/" .. pkgname .. "?author-name=true"
+local authors_url = "https://ctan.org/xml/2.0/authors"
-- change that for different title scheme
local titleformat = "The %s package"
@@ -76,18 +77,52 @@
end)
end
+-- we need to use this method temporarily because of a bug in
+-- CTAN API
+local author_list
+local fetch_author_list = function()
+ if author_list then return author_list end
+ local authors = load_xml(authors_url)
+ author_list = {}
+ for _, author in ipairs(authors:query_selector("author")) do
+ -- save all authors under they ID
+ local id = author:get_attribute("id")
+ author_list[id] = author
+ end
+ return author_list
+end
+
+local process_author = function(author)
+ local current = {}
+ current[#current+1] = author:get_attribute("familyname")
+ current[#current+1] = author:get_attribute("givenname")
+ -- the author is an organization
+ if #current == 1 then
+ return "{" .. current[1] .. "}"
+ elseif #current > 1 then
+ return table.concat(current, ", ")
+ end
+ return nil -- no author
+end
+
+-- get the author name and surname
+local get_author = function(author)
+ local name = process_author(author)
+ if name then return name end
+ -- if the package XML doesn't contain author name,
+ -- we need to fetch the authors list from CTAN and find
+ -- it here
+ local author_list = fetch_author_list()
+ local id = author:get_attribute("id")
+ -- try to find the author id in list of authors
+ -- if everything fails, just return an empty group
+ return process_author(author_list[id]) or "{}"
+end
+
local get_authors = function(a)
local retrieved_authors = {}
for _, author in ipairs(a) do
- local current = {}
- current[#current+1] = author:get_attribute("familyname")
- current[#current+1] = author:get_attribute("givenname")
- -- the author is an organization
- if #current == 1 then
- table.insert(retrieved_authors, "{" .. current[1] .. "}")
- else
- table.insert(retrieved_authors, table.concat(current, ", "))
- end
+ table.insert(retrieved_authors, get_author(author))
end
return table.concat(retrieved_authors," and ")
end
More information about the tex-live-commits
mailing list