From ccf104051349c8620d3d18a9c822e4ea80458f90 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Fri, 10 Feb 2017 13:34:49 +0100 Subject: [PATCH] Added sitemap support on node module. code cleaning. --- .../site/modules/sitemap/files/sitemap.xsl | 141 ++++++++++++++++++ modules/node/cms_node_module.e | 21 +++ modules/sitemap/cms_sitemap_module.e | 61 +------- modules/sitemap/site/files/sitemap.xsl | 141 ++++++++++++++++++ src/hooks/cms_hook_manager.e | 4 +- src/service/cms_api.e | 4 +- tools/install.bat | 12 +- 7 files changed, 322 insertions(+), 62 deletions(-) create mode 100644 examples/demo/site/modules/sitemap/files/sitemap.xsl create mode 100644 modules/sitemap/site/files/sitemap.xsl diff --git a/examples/demo/site/modules/sitemap/files/sitemap.xsl b/examples/demo/site/modules/sitemap/files/sitemap.xsl new file mode 100644 index 0000000..32d983b --- /dev/null +++ b/examples/demo/site/modules/sitemap/files/sitemap.xsl @@ -0,0 +1,141 @@ + + + + + + + XML Sitemap + + + + + +
+ + + + + + + + + + + + + high + + + + + + + +
URLPriorityChange FrequencyLastChange (GMT)
+ + + + + + + + + + + + +
+
+ + +
+
diff --git a/modules/node/cms_node_module.e b/modules/node/cms_node_module.e index 3cc813e..048309c 100644 --- a/modules/node/cms_node_module.e +++ b/modules/node/cms_node_module.e @@ -25,6 +25,8 @@ inherit CMS_RECENT_CHANGES_HOOK + CMS_SITEMAP_HOOK + CMS_TAXONOMY_HOOK create @@ -40,6 +42,7 @@ feature {NONE} -- Initialization package := "core" -- Optional dependencies, mainly for information. put_dependency ({CMS_RECENT_CHANGES_MODULE}, False) + put_dependency ({CMS_SITEMAP_MODULE}, False) put_dependency ({CMS_TAXONOMY_MODULE}, False) end @@ -212,6 +215,7 @@ feature -- Hooks -- Module specific hook, if available. a_hooks.subscribe_to_hook (Current, {CMS_RECENT_CHANGES_HOOK}) + a_hooks.subscribe_to_hook (Current, {CMS_SITEMAP_HOOK}) a_hooks.subscribe_to_hook (Current, {CMS_TAXONOMY_HOOK}) end @@ -388,4 +392,21 @@ feature -- Hooks end end + populate_sitemap (a_sitemap: CMS_SITEMAP) + -- Populate `a_sitemap`. + local + i: CMS_SITEMAP_ITEM + n: CMS_NODE + do + if attached node_api as l_node_api then + across + l_node_api.nodes as ic -- FIXME: do not load all nodes at once! + loop + n := ic.item + create i.make (l_node_api.node_link (n), n.modification_date) + a_sitemap.force (i) + end + end + end + end diff --git a/modules/sitemap/cms_sitemap_module.e b/modules/sitemap/cms_sitemap_module.e index 307af50..c2b9258 100644 --- a/modules/sitemap/cms_sitemap_module.e +++ b/modules/sitemap/cms_sitemap_module.e @@ -49,13 +49,7 @@ feature -- Access: router feature -- Hook sitemap (a_response: CMS_RESPONSE): CMS_SITEMAP - local - l_user: detachable CMS_USER --- lnk: FEED_LINK --- nb: NATURAL_32 --- s: STRING_32 do - l_user := Void -- Public access for the feed! create Result.make (create {DATE_TIME}.make_now_utc) if attached a_response.api.hooks.subscribers ({CMS_SITEMAP_HOOK}) as lst then across @@ -66,44 +60,6 @@ feature -- Hook end end end - --- create l_feed.make ("CMS Recent changes") --- l_feed.set_date (create {DATE_TIME}.make_now_utc) --- nb := a_size --- across --- l_changes as ic --- until --- nb = 0 --- loop --- ch := ic.item --- create l_feed_item.make (ch.link.title) --- l_feed_item.set_date (ch.date) --- --- create s.make_empty --- if attached ch.information as l_information then --- s.append (l_information) --- end --- if attached ch.summary as sum then --- if not s.is_empty then --- s.append ("%N%N") --- end --- s.append (sum) --- end --- l_feed_item.set_description (s) --- if attached ch.categories as lst then --- across --- lst as cats_ic --- loop --- l_feed_item.set_category (cats_ic.item) --- end --- end --- create lnk.make (a_response.absolute_url (ch.link.location, Void)) --- l_feed_item.links.force (lnk, "") --- l_feed.extend (l_feed_item) --- nb := nb - 1 --- end --- l_feed.sort --- Result := l_feed end feature -- Handler @@ -111,13 +67,12 @@ feature -- Handler handle_sitemp_xml (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE) local r: CMS_RESPONSE --- htdate: HTTP_DATE mesg: CMS_CUSTOM_RESPONSE_MESSAGE l_xml: STRING l_cache: CMS_FILE_STRING_8_CACHE do create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) - create l_cache.make (api.files_location.extended ("sitemap.xml")) + create l_cache.make (api.files_location.extended ("modules").extended ("sitemap").extended ("sitemap.xml")) if l_cache.exists and then not l_cache.expired (Void, 7*24*60*60) and then @@ -130,17 +85,17 @@ feature -- Handler elseif attached sitemap (r) as l_sitemap then create l_xml.make (1_024) l_xml.append ("%N") - l_xml.append ("%N") + l_xml.append ("%N") l_xml.append ("%N") across l_sitemap as ic loop - l_xml.append ("%N") - l_xml.append (" " + r.absolute_url (ic.item.link.location, Void) + "%N") - l_xml.append (" "); append_date_output (ic.item.date, l_xml); l_xml.append ("%N") - l_xml.append (" " + ic.item.change_frequency + "%N") - l_xml.append (" " + ic.item.priority.out + "%N") - l_xml.append ("%N") + l_xml.append (" %N") + l_xml.append (" " + r.absolute_url (ic.item.link.location, Void) + "%N") + l_xml.append (" "); append_date_output (ic.item.date, l_xml); l_xml.append ("%N") + l_xml.append (" " + ic.item.change_frequency + "%N") + l_xml.append (" " + ic.item.priority.out + "%N") + l_xml.append (" %N") end l_xml.append ("%N") l_cache.put (l_xml) diff --git a/modules/sitemap/site/files/sitemap.xsl b/modules/sitemap/site/files/sitemap.xsl new file mode 100644 index 0000000..32d983b --- /dev/null +++ b/modules/sitemap/site/files/sitemap.xsl @@ -0,0 +1,141 @@ + + + + + + + XML Sitemap + + + + + +
+ + + + + + + + + + + + + high + + + + + + + +
URLPriorityChange FrequencyLastChange (GMT)
+ + + + + + + + + + + + +
+
+ + +
+
diff --git a/src/hooks/cms_hook_manager.e b/src/hooks/cms_hook_manager.e index 038136e..d24963e 100644 --- a/src/hooks/cms_hook_manager.e +++ b/src/hooks/cms_hook_manager.e @@ -28,6 +28,8 @@ feature -- Change subscribe_to_hook (h: CMS_HOOK; a_hook_type: TYPE [CMS_HOOK]) -- Subscribe `h' to hooks identified by `a_hook_type'. + require + h_is_expected_hook: a_hook_type.attempted (h) = h local lst: detachable LIST [CMS_HOOK] do @@ -49,7 +51,7 @@ invariant all_subscribers /= Void note - copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" + copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" end diff --git a/src/service/cms_api.e b/src/service/cms_api.e index 3c4346f..fb4fefa 100644 --- a/src/service/cms_api.e +++ b/src/service/cms_api.e @@ -792,14 +792,14 @@ feature -- Environment/ module module_resource_location (a_module: CMS_MODULE; a_resource: PATH): PATH -- Location of resource `a_resource' for `a_module'. do - --| site/modules/$modname/$a_name.json + --| site/modules/$modname/$a_resource Result := module_resource_location_by_name (a_module.name, a_resource) end module_resource_location_by_name (a_module_name: READABLE_STRING_GENERAL; a_resource: PATH): PATH -- Location of resource `a_resource' for `a_module'. do - --| site/modules/$modname/$a_name.json + --| site/modules/$modname/$a_resource Result := module_location_by_name (a_module_name).extended_path (a_resource) end diff --git a/tools/install.bat b/tools/install.bat index a0ef659..d395033 100644 --- a/tools/install.bat +++ b/tools/install.bat @@ -50,12 +50,12 @@ set TMP_CONTRIB_DIR=%TMP_TARGET_DIR%\contrib set TMP_UNSTABLE_DIR=%TMP_TARGET_DIR%\unstable echo Install ROC as CMS ewf -%SAFE_RMDIR% %TMP_UNSTABLE_DIR%\library\cms\launcher -%SAFE_RMDIR% %TMP_UNSTABLE_DIR%\library\cms\library -%SAFE_RMDIR% %TMP_UNSTABLE_DIR%\library\cms\src -%SAFE_RMDIR% %TMP_UNSTABLE_DIR%\library\cms\doc -%SAFE_RMDIR% %TMP_UNSTABLE_DIR%\library\cms\modules -%SAFE_RMDIR% %TMP_UNSTABLE_DIR%\library\cms\examples +%SAFE_RMDIR% %TMP_UNSTABLE_DIR%\library\web\cms\launcher +%SAFE_RMDIR% %TMP_UNSTABLE_DIR%\library\web\cms\library +%SAFE_RMDIR% %TMP_UNSTABLE_DIR%\library\web\cms\src +%SAFE_RMDIR% %TMP_UNSTABLE_DIR%\library\web\cms\doc +%SAFE_RMDIR% %TMP_UNSTABLE_DIR%\library\web\cms\modules +%SAFE_RMDIR% %TMP_UNSTABLE_DIR%\library\web\cms\examples %COPYCMD% %TMP_DIR%\launcher %TMP_UNSTABLE_DIR%\library\web\cms\launcher %COPYCMD% %TMP_DIR%\library %TMP_UNSTABLE_DIR%\library\web\cms\library