Skip to content

Commit

Permalink
analyze_html: display the last url of each shortcode
Browse files Browse the repository at this point in the history
This allows for finding examples of where they are used in
the existing site.
  • Loading branch information
ahayzen-kdab committed Feb 1, 2024
1 parent ec44ab5 commit 255f088
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion wagtail_wordpress_import/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self):
self.styles_unique_pages = Counter()
self.classes_unique_pages = Counter()
self.shortcodes_unique_pages = Counter()
self.shortcodes_page_url = {}

@classmethod
def find_all_tags(cls, dom):
Expand Down Expand Up @@ -91,7 +92,7 @@ def find_all_shortcodes(cls, dom):

return shortcodes

def analyze(self, html):
def analyze(self, html, page_url):
self.total += 1

try:
Expand All @@ -117,3 +118,6 @@ def analyze(self, html):
self.styles_unique_pages.update(styles.keys())
self.classes_unique_pages.update(classes.keys())
self.shortcodes_unique_pages.update(shortcodes.keys())

for shortcode in shortcodes.keys():
self.shortcodes_page_url[shortcode] = page_url
3 changes: 2 additions & 1 deletion wagtail_wordpress_import/importers/wordpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ def analyze_html(self, html_analyzer, *, page_types, page_statuses):
):

html_analyzer.analyze(
filter_linebreaks_wp(item.get("content:encoded"))
filter_linebreaks_wp(item.get("content:encoded")),
item.get("link"),
)

def connect_richtext_page_links(self, imported_pages):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ def handle(self, **options):
"Shortcode",
"Pages used on",
"Total occurrences",
"Last URL",
]
for shortcode, total_pages in analyzer.shortcodes_unique_pages.most_common():
shortcodes_table.add_row(
[shortcode, total_pages, analyzer.shortcodes_total[shortcode]]
[shortcode, total_pages, analyzer.shortcodes_total[shortcode], analyzer.shortcodes_page_url[shortcode]]
)

self.stdout.write("Most commonly used shortcodes")
Expand Down

0 comments on commit 255f088

Please sign in to comment.