Skip to content

Commit 34f60e7

Browse files
committed
Consider a 'moved' case where the page has become a landing page for a new section
1 parent 804e115 commit 34f60e7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

audit/gdcd/db/HandleMissingPageIds.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,16 @@ func checkIfPageIdsOverlap(oldPageId string, newPageId string) bool {
116116
// `create-mongodb-user-for-cluster` - is what we're considering the page title
117117
oldPageName := getPageTitleFromId(oldPageId)
118118
newPageName := getPageTitleFromId(newPageId)
119+
newPageSegments := getExtendedPageTitleFromId(newPageName)
119120

120121
// The simplest case is a restructure that moves the pages from one directory to another without any changes.
121122
// If the page name is an exact match, we can return true, because the page title overlaps 100%
122123
if oldPageName == newPageName {
123124
return true
125+
// In some cases, the page may have become a title page for a section, and may now have pages below it. Check
126+
// if the old page name is up a directory level.
127+
} else if contains(newPageSegments, oldPageName) {
128+
return true
124129
} else {
125130
// If it's not a 1:1 move the page without changing the title situation, we can compare the page titles to try
126131
// to figure out if it has enough overlap to be effectively the same page title
@@ -140,6 +145,24 @@ func getPageTitleFromId(pageId string) string {
140145
}
141146
}
142147

148+
func getExtendedPageTitleFromId(pageId string) []string {
149+
parts := strings.Split(pageId, "|")
150+
151+
var titleSegments []string
152+
// Get the last element
153+
if len(parts) > 0 {
154+
lastElement := parts[len(parts)-1] // Access the last index
155+
titleSegments = append(titleSegments, lastElement)
156+
}
157+
// If there are multiple elements, get the second-to-last element. This may contain something that _used_ to match
158+
// the page ID when we are now nesting pages below it
159+
if len(parts) > 1 {
160+
secondToLastElement := parts[len(parts)-2]
161+
titleSegments = append(titleSegments, secondToLastElement)
162+
}
163+
return titleSegments
164+
}
165+
143166
func pageNamesHaveCommonElements(oldPageName string, newPageName string) bool {
144167
// Split the page names by `-` to get the words in the name for common comparison
145168
oldPageNameParts := strings.Split(oldPageName, "-")

0 commit comments

Comments
 (0)