Skip to content

Instantly share code, notes, and snippets.

@atdt
Created June 22, 2016 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atdt/7dc60ff05ea5e7bac20e333b9ae24f78 to your computer and use it in GitHub Desktop.
Save atdt/7dc60ff05ea5e7bac20e333b9ae24f78 to your computer and use it in GitHub Desktop.
--- a/cs1.lua
+++ b/cs1.lua
@@ -25,7 +25,7 @@ delare variables here that have page-wide scope
]]
-local Preview_mode = false; -- flag indicating that we are rendering a preview page (Show preview button)
+local is_preview_result = nil; -- flag indicating that we are rendering a preview page (Show preview button)
--[[--------------------------< F I R S T _ S E T >------------------------------------------------------------
@@ -38,6 +38,13 @@ the for-loop before it reached the actual end of the list.
]]
+local function is_preview_mode ()
+ if ( is_preview_result == nil ) then
+ is_preview_result = ( frame:preprocess( "{{REVISIONID}}" ) == "" )
+ end
+ return is_preview_result
+end
+
local function first_set (list, count)
local i = 1;
while i <= count do -- loop through all items in list
@@ -1795,7 +1802,7 @@ local function archive_url_check (url, date)
if url:match('//web%.archive%.org/save/') then -- if a save command url, we don't want to allow saving of the target page
table.insert( z.message_tail, { set_error( 'archive_url', {'save command'}, true ) } ); -- add error message
- if Preview_mode then
+ if is_preview_mode() then
return url:gsub ('(//web%.archive%.org)/save/', '%1/*/', 1), date; -- preview mode: modify and return ArchiveURL and ArchiveDate
else
return '', ''; -- return empty strings for archiveURL and ArchiveDate
@@ -1825,7 +1832,7 @@ local function archive_url_check (url, date)
end
-- if here something not right so
table.insert( z.message_tail, { set_error( 'archive_url', {err_msg}, true ) } ); -- add error message and
- if Preview_mode then
+ if is_preview_mode() then
return url, date; -- preview mode so return archiveURL and ArchiveDate
else
return '', ''; -- return empty strings for archiveURL and ArchiveDate
@@ -3282,14 +3289,6 @@ function cs1.citation(frame)
get_coins_pages = metadata.get_coins_pages;
COinS = metadata.COinS;
-
- Preview_mode = frame:preprocess('{{REVISIONID}}'); -- use magic word to get revision id
- if is_set (Preview_mode) then -- if there is a value then this is not a preiview
- Preview_mode = false;
- else
- Preview_mode = true; -- no value (nil or empty string) so this is a preview
- end
-
local args = {};
local suggestions = {};
local error_text, error_state;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment