Skip to content

Commit 83f9bb7

Browse files
committed
analyze_html: display the last url of each shortcode
This allows for finding examples of where they are used in the existing site.
1 parent ec44ab5 commit 83f9bb7

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

wagtail_wordpress_import/analysis.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def __init__(self):
2020
self.styles_unique_pages = Counter()
2121
self.classes_unique_pages = Counter()
2222
self.shortcodes_unique_pages = Counter()
23+
self.shortcodes_page_url = {}
2324

2425
@classmethod
2526
def find_all_tags(cls, dom):
@@ -91,7 +92,7 @@ def find_all_shortcodes(cls, dom):
9192

9293
return shortcodes
9394

94-
def analyze(self, html):
95+
def analyze(self, html, page_url):
9596
self.total += 1
9697

9798
try:
@@ -117,3 +118,6 @@ def analyze(self, html):
117118
self.styles_unique_pages.update(styles.keys())
118119
self.classes_unique_pages.update(classes.keys())
119120
self.shortcodes_unique_pages.update(shortcodes.keys())
121+
122+
for shortcode in shortcodes.keys():
123+
self.shortcodes_page_url[shortcode] = page_url

wagtail_wordpress_import/importers/wordpress.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ def analyze_html(self, html_analyzer, *, page_types, page_statuses):
263263
item.get("wp:post_type") in page_types
264264
and item.get("wp:status") in page_statuses
265265
):
266-
267266
html_analyzer.analyze(
268-
filter_linebreaks_wp(item.get("content:encoded"))
267+
filter_linebreaks_wp(item.get("content:encoded")),
268+
item.get("link"),
269269
)
270270

271271
def connect_richtext_page_links(self, imported_pages):

wagtail_wordpress_import/management/commands/analyze_html_content.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ def handle(self, **options):
112112
"Shortcode",
113113
"Pages used on",
114114
"Total occurrences",
115+
"Last URL",
115116
]
116117
for shortcode, total_pages in analyzer.shortcodes_unique_pages.most_common():
117118
shortcodes_table.add_row(
118-
[shortcode, total_pages, analyzer.shortcodes_total[shortcode]]
119+
[shortcode, total_pages, analyzer.shortcodes_total[shortcode], analyzer.shortcodes_page_url[shortcode]]
119120
)
120121

121122
self.stdout.write("Most commonly used shortcodes")

0 commit comments

Comments
 (0)