View Single Post
Old 08-01-2022, 09:59 AM   #7385
JimmXinu
Plugin Developer
JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.
 
JimmXinu's Avatar
 
Posts: 6,984
Karma: 4604635
Join Date: Dec 2011
Location: Midwest USA
Device: Kobo Clara Colour running KOReader
Quote:
Originally Posted by culytera View Post
Back again with another question, is it possible to format the date depending on whether the date published and date updated are the same or not?
...
Then I was thinking of comparing each published/updated month/day/year to form the final date, but I don't know if replace_metadata can take the value from other variables. Don't know why I can't just be satisfied with my current layout but here we are lol
(date)_format only works on the three standard date entries: dateCreated, datePublished, and dateUpdated. The include_in_X mechanism make a list of strings, so it's not practical to change that.

And each replace_metadata line only works on one value at a time without knowledge of any other entry.

But I think it's possible to do what you want by using the _LIST feature of replace_metadata, this seems to work for me:
Code:
datePublished_format:%%B %%d, %%Y
dateUpdated_format:%%B %%d, %%Y
add_to_extra_valid_entries:,dateRange
include_in_dateRange:datePublished,dateUpdated
keep_in_order_dateRange:true

add_to_replace_metadata:
# same year      1          2            3        4          5
 dateRange_LIST=>([^\s]+)\s+(\d{1,2}),\s+(\d{4}), ([^\s]+)\s+(\d{1,2}),\s+\3=>\1 \2-\4 \5, \3
# same month     1          2              3            4
 dateRange_LIST=>([^\s]+)\s+(\d{1,2})-\1\s+(\d{1,2}),\s+(\d{4})=>\1 \2-\3, \4
# don't need regexp for date day, handled by de-dup.
  1. Explicitly set date formats--some sites also include times, those will be lost unfortunately
  2. Make new entry dateRange
  3. Populate dateRange with datePublished, dateUpdated
  4. Keep dateRange in order (otherwise alphabetized, not date ordered)
  5. Replace on dateRange_LIST (the whole list) looking for the same year -- note \3 matching the second year
  6. Replace on dateRange_LIST (the whole list) looking for the same month ONLY on strings that already had the same year -- note \1 matching the second month and - instead of ,\s+ between them.
  7. datePublished == dateUpdated and stories without dateUpdated will show up in dateRange as just one date.
JimmXinu is offline   Reply With Quote