make journals in roam date format be recognized by journals page

This commit is contained in:
Nik V 2020-11-27 19:18:51 -08:00
parent 6e45be9b73
commit 71f0a3c4e4
2 changed files with 19 additions and 2 deletions

View file

@ -187,7 +187,7 @@ def all_nodes(include_journals=True):
# remove journals if so desired.
if not include_journals:
nodes = [node for node in nodes if not re.match('[0-9]+?-[0-9]+?-[0-9]+?', node.wikilink)]
nodes = [node for node in nodes if not util.is_journal(node.wikilink)]
# TODO: experiment with other ranking.
# return sorted(nodes, key=lambda x: -x.size())
@ -201,7 +201,7 @@ def all_users():
def all_journals():
# hack hack.
nodes = all_nodes()
nodes = [node for node in nodes if re.match('[0-9]+?-[0-9]+?-[0-9]+?', node.wikilink)]
nodes = [node for node in nodes if util.is_journal(node.wikilink)]
return sorted(nodes, key=attrgetter('wikilink'), reverse=True)
def nodes_by_wikilink(wikilink):

View file

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import re
def canonical_wikilink(wikilink):
# hack hack
@ -22,3 +23,19 @@ def canonical_wikilink(wikilink):
.replace('/', '-')
)
return wikilink
def is_journal(wikilink):
date_regexes = [
# iso format
'[0-9]{4}-[0-9]{2}-[0-9]{2}',
# roam format (what a monstrosity!)
'(January|February|March|April|May|June|July|August|September|October|November|December) [0-9]{1,2}(st|nd|th), [0-9]{4}',
# roam format (sanitzed for filenames)
'(january|february|march|april|may|june|july|august|september|october|november|december)-[0-9]{1,2}(st|nd|th)-[0-9]{4}',
]
# combine all the date regexes into one super regex
combined_date_regex = re.compile(f'^({"|".join(date_regexes)})$')
return combined_date_regex.match(wikilink)