Skip to content

Commit f79f1ff

Browse files
committed
Refactored getAttributes() logic to return container DataObject
Updated the `getAttributes()` function so that the root `DataObject` is created by the function itself. This makes it more consistent with the other local functions, and cleans up the calling code.
1 parent dcd1b4c commit f79f1ff

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

OnTopic.AspNetCore.Mvc/Controllers/SitemapController.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,7 @@ private IEnumerable<XElement> AddTopic(Topic topic, bool includeMetadata = false
195195
new XElement(_sitemapNamespace + "lastmod", lastModified.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)),
196196
new XElement(_sitemapNamespace + "priority", 1),
197197
includeMetadata? new XElement(_pagemapNamespace + "PageMap",
198-
new XElement(_pagemapNamespace + "DataObject",
199-
new XAttribute("type", topic.ContentType?? "Page"),
200-
getAttributes()
201-
),
198+
getAttributes(),
202199
getRelationships(),
203200
getReferences()
204201
) : null
@@ -222,14 +219,17 @@ private IEnumerable<XElement> AddTopic(Topic topic, bool includeMetadata = false
222219
/*------------------------------------------------------------------------------------------------------------------------
223220
| Get attributes
224221
\-----------------------------------------------------------------------------------------------------------------------*/
225-
IEnumerable<XElement> getAttributes() =>
226-
from attribute in topic.Attributes
227-
where !ExcludeAttributes.Contains(attribute.Key, StringComparer.OrdinalIgnoreCase)
228-
where topic.Attributes.GetValue(attribute.Key)?.Length < 256
229-
select new XElement(_pagemapNamespace + "Attribute",
230-
new XAttribute("name", attribute.Key),
231-
new XText(topic.Attributes.GetValue(attribute.Key))
232-
);
222+
XElement getAttributes() =>
223+
new XElement(_pagemapNamespace + "DataObject",
224+
new XAttribute("type", "Attributes"),
225+
from attribute in topic.Attributes
226+
where !ExcludeAttributes.Contains(attribute.Key, StringComparer.OrdinalIgnoreCase)
227+
where topic.Attributes.GetValue(attribute.Key)?.Length < 256
228+
select new XElement(_pagemapNamespace + "Attribute",
229+
new XAttribute("name", attribute.Key),
230+
new XText(topic.Attributes.GetValue(attribute.Key))
231+
)
232+
);
233233

234234
/*------------------------------------------------------------------------------------------------------------------------
235235
| Get relationships

0 commit comments

Comments
 (0)