workarea-sitemaps 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.gitignore +15 -0
  7. data/.rspec +2 -0
  8. data/.yardopts +1 -0
  9. data/CHANGELOG.md +228 -0
  10. data/CODE_OF_CONDUCT.md +3 -0
  11. data/CONTRIBUTING.md +3 -0
  12. data/Gemfile +6 -0
  13. data/LICENSE +52 -0
  14. data/README.md +40 -0
  15. data/Rakefile +32 -0
  16. data/app/models/workarea/navigation/taxon.decorator +7 -0
  17. data/app/models/workarea/sitemap/link.rb +53 -0
  18. data/app/models/workarea/sitemap.rb +20 -0
  19. data/app/views/workarea/storefront/pages/_robots_sitemaps.text.erb +1 -0
  20. data/app/workers/workarea/generate_sitemaps.rb +71 -0
  21. data/bin/rails +18 -0
  22. data/config/initializers/appends.rb +4 -0
  23. data/config/initializers/dragonfly.rb +9 -0
  24. data/config/initializers/scheduled_jobs.rb +6 -0
  25. data/config/routes.rb +9 -0
  26. data/lib/workarea/asset_endpoints/sitemaps.rb +9 -0
  27. data/lib/workarea/sitemaps/engine.rb +8 -0
  28. data/lib/workarea/sitemaps/version.rb +5 -0
  29. data/lib/workarea/sitemaps.rb +13 -0
  30. data/test/dummy/README.rdoc +28 -0
  31. data/test/dummy/Rakefile +6 -0
  32. data/test/dummy/app/assets/images/.keep +0 -0
  33. data/test/dummy/app/assets/javascripts/application.js +13 -0
  34. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  35. data/test/dummy/app/controllers/application_controller.rb +5 -0
  36. data/test/dummy/app/controllers/concerns/.keep +0 -0
  37. data/test/dummy/app/helpers/application_helper.rb +2 -0
  38. data/test/dummy/app/mailers/.keep +0 -0
  39. data/test/dummy/app/models/.keep +0 -0
  40. data/test/dummy/app/models/concerns/.keep +0 -0
  41. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  42. data/test/dummy/bin/bundle +3 -0
  43. data/test/dummy/bin/rails +4 -0
  44. data/test/dummy/bin/rake +4 -0
  45. data/test/dummy/bin/setup +34 -0
  46. data/test/dummy/bin/update +29 -0
  47. data/test/dummy/config/application.rb +22 -0
  48. data/test/dummy/config/boot.rb +5 -0
  49. data/test/dummy/config/cable.yml +9 -0
  50. data/test/dummy/config/environment.rb +5 -0
  51. data/test/dummy/config/environments/development.rb +54 -0
  52. data/test/dummy/config/environments/production.rb +86 -0
  53. data/test/dummy/config/environments/test.rb +43 -0
  54. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  55. data/test/dummy/config/initializers/assets.rb +11 -0
  56. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  57. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  58. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  59. data/test/dummy/config/initializers/inflections.rb +16 -0
  60. data/test/dummy/config/initializers/mime_types.rb +4 -0
  61. data/test/dummy/config/initializers/new_framework_defaults.rb +17 -0
  62. data/test/dummy/config/initializers/session_store.rb +3 -0
  63. data/test/dummy/config/initializers/workarea.rb +8 -0
  64. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  65. data/test/dummy/config/locales/en.yml +23 -0
  66. data/test/dummy/config/puma.rb +47 -0
  67. data/test/dummy/config/routes.rb +5 -0
  68. data/test/dummy/config/secrets.yml +22 -0
  69. data/test/dummy/config/spring.rb +6 -0
  70. data/test/dummy/config.ru +4 -0
  71. data/test/dummy/lib/assets/.keep +0 -0
  72. data/test/dummy/log/.keep +0 -0
  73. data/test/dummy/public/404.html +67 -0
  74. data/test/dummy/public/422.html +67 -0
  75. data/test/dummy/public/500.html +66 -0
  76. data/test/dummy/public/favicon.ico +1 -0
  77. data/test/integration/workarea/storefront/sitemaps_integration_test.rb +53 -0
  78. data/test/models/workarea/navigation/taxon_test.decorator +22 -0
  79. data/test/models/workarea/sitemap/link_test.rb +58 -0
  80. data/test/test_helper.rb +10 -0
  81. data/test/workers/workarea/generate_sitemaps_test.rb +81 -0
  82. data/workarea-sitemaps.gemspec +22 -0
  83. metadata +153 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a849e41bff94936faa32f32f815fcfc1f2538320a80428c338c798aad7fa72fd
4
+ data.tar.gz: 105d71537ba4ef0cfc373d1808897d861b5df24a950046e320401db9a5d03043
5
+ SHA512:
6
+ metadata.gz: 4049a90e3f0c579dd91fbe7d226ef3fb07034f87e15cd09d911423b2e5c17faceda0a4612c79711eab3306b5d48a6aeec26ca0c0aa22f1844a90cd2efa30ae70
7
+ data.tar.gz: fdc7d1f30ed4e57bed5c91cc0e4ec0530e431baf7bfae02509073842315936a16a072fd7f26bd5543ed205c9c8a1a1523a33d3d3b03013f270296c64d5f33433
data/.editorconfig ADDED
@@ -0,0 +1,20 @@
1
+ # editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ end_of_line = lf
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [{*.rb,*.haml,*.decorator,*.yml,*.yaml,*.jbuilder}]
12
+ indent_size = 2
13
+ indent_style = space
14
+
15
+ [{*.js,*.jst,*.ejs,*.scss}]
16
+ indent_size = 4
17
+
18
+ [*.md]
19
+ indent_size = 4
20
+ trim_trailing_whitespace = false
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve Workarea
4
+ title: ''
5
+ labels: bug
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ ⚠️**Before you create**⚠️
11
+ Please verify the issue you're experiencing is not part of your Workarea project customizations. The best way to do this is with a [vanilla Workarea installation](https://developer.workarea.com/articles/create-a-new-host-application.html). This will help us spend time on fixes/improvements for the whole community. Thank you!
12
+
13
+ **Describe the bug**
14
+ A clear and concise description of what the bug is.
15
+
16
+ **To Reproduce**
17
+ Steps to reproduce the behavior:
18
+ 1. Go to '...'
19
+ 2. Click on '....'
20
+ 3. Scroll down to '....'
21
+ 4. See error
22
+
23
+ **Expected behavior**
24
+ A clear and concise description of what you expected to happen.
25
+
26
+ **Workarea Setup (please complete the following information):**
27
+ - Workarea Version: [e.g. v3.4.6]
28
+ - Plugins [e.g. workarea-blog, workarea-sitemaps]
29
+
30
+ **Attachments**
31
+ If applicable, add any attachments to help explain your problem, things like:
32
+ - screenshots
33
+ - Gemfile.lock
34
+ - test cases
35
+
36
+ **Additional context**
37
+ Add any other context about the problem here.
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Documentation request
3
+ about: Suggest documentation
4
+ title: ''
5
+ labels: documentation
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your documentation related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm confused by [...]
12
+
13
+ **Describe the article you'd like**
14
+ A clear and concise description of what would be in the documentation article.
15
+
16
+ **Additional context**
17
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for Workarea
4
+ title: ''
5
+ labels: enhancement
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ .bundle/
2
+ Gemfile.lock
3
+ .sass-cache/
4
+ log/*.log
5
+ pkg/
6
+ test/dummy/public/system/dragonfly
7
+ test/dummy/db/*.sqlite3
8
+ test/dummy/log/*.log
9
+ test/dummy/tmp/
10
+ test/dummy/.sass-cache
11
+ .DS_Store
12
+ node_modules
13
+ test/reports
14
+ package.json
15
+ yarn.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --failure-exit-code 0
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --files CHANGELOG.md
data/CHANGELOG.md ADDED
@@ -0,0 +1,228 @@
1
+ Workarea Sitemaps 2.1.6 (2019-08-21)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * Open Source!
5
+
6
+
7
+
8
+ Workarea Sitemaps 2.1.5 (2019-07-23)
9
+ --------------------------------------------------------------------------------
10
+
11
+ * Parse Path URLs in Sitemap
12
+
13
+ When a URL for a `Navigation::Taxon` is not fully-qualified, the
14
+ generator builds these links as `://page-name` in the sitemap. To
15
+ resolve this, `Sitemap::Link` now checks for whether the URL is fully
16
+ qualified before attempting to use its parsed `#host` and `#scheme` in
17
+ the generation for the sitemap.
18
+
19
+ SITEMAPS-22
20
+ Tom Scott
21
+
22
+
23
+
24
+ Workarea Sitemaps 2.1.4 (2019-04-02)
25
+ --------------------------------------------------------------------------------
26
+
27
+ * Only Track HTTP Links in Sitemap
28
+
29
+ Non-HTTP links, like `tel:` and `mailto:`, are invalid within a
30
+ Google-compatible XML sitemap. Omit any taxonomy that points to these
31
+ URLs in the sitemap by checking for the presence of "http" or "/" at the
32
+ beginning of the URL, or whether the Taxon is linked to a Navigable item.
33
+ Introduce a new predicate method, `Navigation::Taxon#show_in_sitemap?`,
34
+ to wrap up all the logic for whether a taxon should be included in the
35
+ generated Google Sitemap XML.
36
+
37
+ SITEMAPS-20
38
+ Tom Scott
39
+
40
+
41
+
42
+ Workarea Sitemaps 2.1.3 (2019-03-19)
43
+ --------------------------------------------------------------------------------
44
+
45
+ * Remove Inactive Products From Generated Sitemap
46
+
47
+ Add the `Catalog::Product.active_with_variants` scope and use it in
48
+ `GenerateSitemaps` to prevent products that have no variants appearing
49
+ in the sitemap just because they have `active: true` set on them.
50
+
51
+ SITEMAPS-21
52
+ Tom Scott
53
+
54
+ * Update for workarea v3.4 compatibility
55
+
56
+ SITEMAPS-19
57
+ Matt Duffy
58
+
59
+
60
+
61
+ Workarea Sitemaps 2.1.2 (2019-01-08)
62
+ --------------------------------------------------------------------------------
63
+
64
+ * Update README
65
+
66
+ SITEMAPS-18
67
+ Curt Howard
68
+
69
+
70
+
71
+ Workarea Sitemaps 2.1.1 (2018-10-30)
72
+ --------------------------------------------------------------------------------
73
+
74
+ * Fix External Links in Sitemap
75
+
76
+ When taxonomy contains a link that is external (e.g., to an alternative
77
+ site or subdomain, like `https://blog.yourclient.com`), the
78
+ `Workarea::GenerateSitemaps` worker was mistakenly applying the default
79
+ configured host for the application to each entry. Create a new
80
+ `Sitemap::Link` class that parses the URL into a URI, if given, or
81
+ reverts back to the original code of finding the route path and using
82
+ that as the entry. Workarea also configures a `:host` for every URL in
83
+ the sitemap, rather than relying on `SitemapGenerator`'s OOB behavior
84
+ of setting the `default_host` for all entries.
85
+
86
+ SITEMAPS-16
87
+ Tom Scott
88
+
89
+
90
+
91
+ Workarea Sitemaps 2.1.0 (2018-05-24)
92
+ --------------------------------------------------------------------------------
93
+
94
+ * Leverage Workarea Changelog task
95
+
96
+ ECOMMERCE-5355
97
+ Curt Howard
98
+
99
+ * Fix for headless Chrome
100
+
101
+ We strip HTTP cache headers in tests now. To test HTTP caching headers, you
102
+ must enable them.
103
+ Ben Crouse
104
+
105
+
106
+
107
+ Workarea Sitemaps 2.0.1 (2017-10-31)
108
+ --------------------------------------------------------------------------------
109
+
110
+ * Move configuration into initializers
111
+
112
+ SITEMAPS-15
113
+ Matt Duffy
114
+
115
+
116
+ Workarea Sitemaps 2.0.0 (2017-05-01)
117
+ --------------------------------------------------------------------------------
118
+
119
+ * Remove lastmod and priority from sitemap entries
120
+
121
+ These aren't being accurately kept up to date and search engines ignore
122
+ them anyways.
123
+
124
+ SITEMAPS-10
125
+ Ben Crouse
126
+
127
+ * Allow homepage in sitemap
128
+
129
+ According to googling around, this can't hurt and may help.
130
+
131
+ SITEMAPS-9
132
+ Ben Crouse
133
+
134
+ * Bump sitemap_generator dependency
135
+
136
+ SITEMAPS-8
137
+ Ben Crouse
138
+
139
+ * Cleanup namespace (minor)
140
+
141
+ SITEMAPS-8
142
+ Ben Crouse
143
+
144
+ * Convert specs to minitest and get them passing
145
+
146
+ SITEMAPS-8
147
+ Ben Crouse
148
+
149
+
150
+ WebLinc Sitemaps 1.0.3 (2016-10-25)
151
+ --------------------------------------------------------------------------------
152
+
153
+ * Use https in the default host
154
+
155
+ SITEMAPS-5
156
+ Ben Crouse
157
+
158
+ * Fix Cache-Control header set too long
159
+
160
+ This causes bots to hang on to the cache for too long and therefore not index changes to the sitemap content.
161
+
162
+ The default value from Dragonfly is good for most use cases, but sitemaps are updated daily.
163
+
164
+ SITEMAPS-4
165
+ Ben Crouse
166
+
167
+ * Fix Cache-Control header set too long
168
+
169
+ This causes bots to hang on to the cache for too long and therefore not index changes to the sitemap content.
170
+
171
+ The default value from Dragonfly is good for most use cases, but sitemaps are updated daily.
172
+
173
+ SITEMAPS-4
174
+ Ben Crouse
175
+
176
+
177
+ WebLinc Sitemaps 1.0.2 (2016-06-13)
178
+ --------------------------------------------------------------------------------
179
+
180
+ * Fix Cache-Control header set too long
181
+
182
+ This causes bots to hang on to the cache for too long and therefore not index changes to the sitemap content.
183
+
184
+ The default value from Dragonfly is good for most use cases, but sitemaps are updated daily.
185
+
186
+ SITEMAPS-4
187
+ Ben Crouse
188
+
189
+
190
+ WebLinc Sitemaps 1.0.1 (2016-04-05)
191
+ --------------------------------------------------------------------------------
192
+
193
+
194
+ WebLinc Sitemaps 1.0.0 (January 13, 2016)
195
+ --------------------------------------------------------------------------------
196
+
197
+ * Update for compatibility with WebLinc 2.0
198
+
199
+ * Add default_url_option to fix errors when running the worker
200
+
201
+ SITEMAPS-3
202
+
203
+
204
+ WebLinc Sitemaps 0.5.0 (July 12, 2015)
205
+ --------------------------------------------------------------------------------
206
+
207
+ * Update for compatibility with weblinc 0.10 and constrain to weblinc >= 0.10
208
+
209
+ 99e26beca229a9c7e483a92cbdf7963e06eb7d0a
210
+ 2b83f6641e5e3ebee981aa9175199df45d5e173e
211
+
212
+
213
+ WebLinc Sitemaps 0.4.0 (June 1, 2015)
214
+ --------------------------------------------------------------------------------
215
+
216
+ * Update for compatibility and consistency with weblinc 0.9.0.
217
+
218
+
219
+ WebLinc Sitemaps 0.3.0 (April 10, 2015)
220
+ --------------------------------------------------------------------------------
221
+
222
+ * Update testing environment for compatibility with WebLinc 0.8.0.
223
+
224
+ * Use new decorator style for consistency with WebLinc 0.8.0.
225
+
226
+ * Remove gems server secrets for consistency with WebLinc 0.8.0.
227
+
228
+ * Add sitemap link to robots.txt.
@@ -0,0 +1,3 @@
1
+ View this plugin's code of conduct here:
2
+
3
+ <https://github.com/workarea-commerce/workarea/blob/master/CODE_OF_CONDUCT.md>
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,3 @@
1
+ View this plugin's contribution guidelines here:
2
+
3
+ <https://github.com/workarea-commerce/workarea/blob/master/CONTRIBUTING.md>
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "git@github.com:#{repo}.git" }
3
+
4
+ gemspec
5
+
6
+ gem 'workarea'
data/LICENSE ADDED
@@ -0,0 +1,52 @@
1
+ WebLinc
2
+ Business Source License
3
+
4
+ Licensor: WebLinc Corporation, 22 S. 3rd Street, 2nd Floor, Philadelphia PA 19106
5
+
6
+ Licensed Work: Workarea Commerce Platform
7
+ The Licensed Work is (c) 2019 WebLinc Corporation
8
+
9
+ Additional Use Grant:
10
+ You may make production use of the Licensed Work without an additional license agreement with WebLinc so long as you do not use the Licensed Work for a Commerce Service.
11
+
12
+ A "Commerce Service" is a commercial offering that allows third parties (other than your employees and contractors) to access the functionality of the Licensed Work by creating or managing commerce functionality, the products, taxonomy, assets and/or content of which are controlled by such third parties.
13
+
14
+ For information about obtaining an additional license agreement with WebLinc, contact licensing@workarea.com.
15
+
16
+ Change Date: 2019-08-20
17
+
18
+ Change License: Version 2.0 or later of the GNU General Public License as published by the Free Software Foundation
19
+
20
+ Terms
21
+
22
+ The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
23
+
24
+ Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate.
25
+
26
+ If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.
27
+
28
+ All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.
29
+
30
+ You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work.
31
+
32
+ Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.
33
+
34
+ This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License). TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE. MariaDB hereby grants you permission to use this License’s text to license your works and to refer to it using the trademark "Business Source License" as long as you comply with the Covenants of Licensor below.
35
+
36
+ Covenants of Licensor
37
+ In consideration of the right to use this License’s text and the "Business Source License" name and trademark, Licensor covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor:
38
+
39
+ To specify as the Change License the GPL Version 2.0 or any later version, or a license that is compatible with GPL Version 2.0 or a later version, where "compatible" means that software provided under the Change License can be included in a program with software provided under GPL Version 2.0 or a later version. Licensor may specify additional Change Licenses without limitation.
40
+
41
+ To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the right granted in this License, as the Additional Use Grant; or (b) insert the text "None."
42
+
43
+ To specify a Change Date.
44
+
45
+ Not to modify this License in any other way.
46
+
47
+ Notice
48
+ The Business Source License (this document, or the "License") is not an Open Source license. However, the Licensed Work will eventually be made available under an Open Source License, as stated in this License.
49
+
50
+ For more information on the use of the Business Source License generally, please visit the Adopting and Developing Business Source License FAQ.
51
+
52
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. "Business Source License" is a trademark of MariaDB Corporation Ab.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ Workarea Sitemaps
2
+ ================================================================================
3
+
4
+ A Workarea Commerce plugin that automatically adds search-engine friendly sitemaps to your site via `sitemap.xml.gz` and `sitemap:index.xml.gz` files.
5
+
6
+ Overview
7
+ --------------------------------------------------------------------------------
8
+
9
+ * Provides `sitemap.xml.gz`, `sitemap:index.xml.gz`, and `robots.txt` files
10
+ * Automatically generated each morning at 5AM, by default
11
+ * Provide configurable file caching via Dragonfly
12
+ * Indexes all active products and navigation taxons
13
+
14
+ Getting Started
15
+ --------------------------------------------------------------------------------
16
+
17
+ Add the gem to your application's Gemfile:
18
+
19
+ ```ruby
20
+ # ...
21
+ gem 'workarea-sitemaps'
22
+ # ...
23
+ ```
24
+
25
+ Update your application's bundle.
26
+
27
+ ```bash
28
+ cd path/to/application
29
+ bundle
30
+ ```
31
+
32
+ Workarea Commerce Documentation
33
+ --------------------------------------------------------------------------------
34
+
35
+ See [https://developer.workarea.com](https://developer.workarea.com) for Workarea Commerce documentation.
36
+
37
+ License
38
+ --------------------------------------------------------------------------------
39
+
40
+ Workarea Sitemaps is released under the [Business Software License](LICENSE)
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
9
+ load 'rails/tasks/engine.rake'
10
+ load 'rails/tasks/statistics.rake'
11
+ load 'workarea/changelog.rake'
12
+
13
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
14
+ require 'workarea/sitemaps/version'
15
+
16
+ desc "Release version #{Workarea::Sitemaps::VERSION} of the gem"
17
+ task :release do
18
+ host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
19
+
20
+ #Rake::Task['workarea:changelog'].execute
21
+ #system 'git add CHANGELOG.md'
22
+ #system 'git commit -m "Update CHANGELOG"'
23
+ #system 'git push origin HEAD'
24
+
25
+ system "git tag -a v#{Workarea::Sitemaps::VERSION} -m 'Tagging #{Workarea::Sitemaps::VERSION}'"
26
+ system 'git push --tags'
27
+
28
+ system 'gem build workarea-sitemaps.gemspec'
29
+ system "gem push workarea-sitemaps-#{Workarea::Sitemaps::VERSION}.gem"
30
+ system "gem push workarea-sitemaps-#{Workarea::Sitemaps::VERSION}.gem --host #{host}"
31
+ system "rm workarea-sitemaps-#{Workarea::Sitemaps::VERSION}.gem"
32
+ end
@@ -0,0 +1,7 @@
1
+ module Workarea
2
+ decorate Navigation::Taxon, with: :sitemaps do
3
+ def show_in_sitemap?
4
+ !placeholder? && active? && (navigable.present? || url.to_s.start_with?('http', '/'))
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,53 @@
1
+ module Workarea
2
+ class Sitemap
3
+ # Model object for representing a single link in the sitemap. A
4
+ # sitemap XML file is composed of +<url />+ elements, and this class
5
+ # helps to define the data that ends up in there.
6
+ class Link
7
+ delegate_missing_to :@taxon
8
+
9
+ # @param [Workarea::Navigation::Taxon] taxon - Model this link is based on
10
+ # @param [Workarea::GenerateSitemaps] generator - Worker class this link was instantiated from.
11
+ def initialize(taxon:, generator:)
12
+ @taxon = taxon
13
+ @generator = generator
14
+ end
15
+
16
+ # Return the parsed +host+ from the given URL, or the default host
17
+ # (+Workarea.config.host+) if a +Navigable+ model is being linked
18
+ # to.
19
+ def host
20
+ return default_host unless fully_qualified_url?
21
+ "#{uri.scheme}://#{uri.host}"
22
+ end
23
+
24
+ # Return the route path for the +Navigable+ model that is linked
25
+ # to in this taxon, or the +url+ that was hard-coded into the
26
+ # taxon at creation.
27
+ def path
28
+ return uri.path if url?
29
+
30
+ @generator.send(route, navigable_slug)
31
+ end
32
+
33
+ private
34
+
35
+ def route
36
+ @route ||= "#{resource_name}_path"
37
+ end
38
+
39
+ def uri
40
+ @uri ||= URI.parse(url)
41
+ end
42
+
43
+ def default_host
44
+ scheme = Rails.configuration.force_ssl ? 'https' : 'http'
45
+ "#{scheme}://#{Workarea.config.host}"
46
+ end
47
+
48
+ def fully_qualified_url?
49
+ url? && uri.host.present? && uri.scheme.present?
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,20 @@
1
+ module Workarea
2
+ class Sitemap
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ extend Dragonfly::Model
6
+
7
+ field :file_uid, type: String
8
+ field :index, type: String
9
+
10
+ dragonfly_accessor :file, app: :workarea
11
+
12
+ def self.find_or_initialize_by_index(index)
13
+ find_by_index(index) || new(index: index)
14
+ end
15
+
16
+ def self.find_by_index(index)
17
+ where(index: index).first
18
+ end
19
+ end
20
+ end
@@ -0,0 +1 @@
1
+ Sitemap: https://<%= Workarea.config.host %>/sitemap.xml.gz
@@ -0,0 +1,71 @@
1
+ module Workarea
2
+ class GenerateSitemaps
3
+ include Sidekiq::Worker
4
+ include Storefront::Engine.routes.url_helpers
5
+
6
+ TMP_DIR = Rails.root.join('tmp', 'sitemaps')
7
+
8
+ def perform(*)
9
+ begin
10
+ create_sitemap
11
+ store_sitemap
12
+
13
+ SitemapGenerator::Sitemap.ping_search_engines if Rails.env.production?
14
+ ensure
15
+ FileUtils.rm_rf(TMP_DIR)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def create_sitemap
22
+ per_batch = 100
23
+ generator = self
24
+
25
+ SitemapGenerator::Sitemap.default_host = "https://#{Workarea.config.host}"
26
+ SitemapGenerator::Sitemap.public_path = TMP_DIR
27
+ SitemapGenerator::Sitemap.create do
28
+ #
29
+ # Products
30
+ #
31
+ #
32
+ Catalog::Product.active.each_by(per_batch) do |product|
33
+ next unless product.active?
34
+ add generator.product_path(product), changefreq: 'daily'
35
+ end
36
+
37
+ #
38
+ # Navigation Links
39
+ #
40
+ #
41
+ Navigation::Taxon.all.each_by(per_batch) do |taxon|
42
+ next unless taxon.show_in_sitemap?
43
+
44
+ entry = Sitemap::Link.new(taxon: taxon, generator: generator)
45
+
46
+ add entry.path, changefreq: 'weekly', host: entry.host
47
+ end
48
+ end
49
+ end
50
+
51
+ def store_sitemap
52
+ Dir[File.join(TMP_DIR, '*.xml.gz')].each do |path|
53
+ file_name = path.split('/').last
54
+ matches = /\d/.match(file_name) || []
55
+ index = matches[0]
56
+
57
+ sitemap = Workarea::Sitemap.find_or_initialize_by_index(index)
58
+ sitemap.file = File.new(path)
59
+ sitemap.save!
60
+ end
61
+ end
62
+
63
+ def default_url_options
64
+ { locale: locale }
65
+ end
66
+
67
+ def locale
68
+ @locale ||= ::I18n.locale != ::I18n.default_locale ? ::I18n.locale : nil
69
+ end
70
+ end
71
+ end
data/bin/rails ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
6
+ ENGINE_PATH = File.expand_path('../../lib/farts/engine', __FILE__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'action_controller/railtie'
13
+ require 'action_view/railtie'
14
+ require 'action_mailer/railtie'
15
+ require 'rails/test_unit/railtie'
16
+ require 'sprockets/railtie'
17
+
18
+ require 'rails/engine/commands'