From af982589fa7bcb213e20ca78ab2a9a366e997a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Rusiczki?= Date: Tue, 25 Apr 2023 21:44:12 +0300 Subject: [PATCH 1/3] Add Procfile, maybe someday... --- app/Procfile.dev | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/Procfile.dev diff --git a/app/Procfile.dev b/app/Procfile.dev new file mode 100644 index 00000000..d2d04686 --- /dev/null +++ b/app/Procfile.dev @@ -0,0 +1,3 @@ +backend: bex rails s +frontend: bin/vite dev +sidekiq: bex sidekiq From 4e8888d7258f56be03d842ac2cd7fa2e5f4448d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Rusiczki?= Date: Tue, 25 Apr 2023 21:46:04 +0300 Subject: [PATCH 2/3] Rename keyboardShortcuts to navigationShortcuts * In preparation for swipe events --- app/javascript/photos/show.vue | 36 +++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/app/javascript/photos/show.vue b/app/javascript/photos/show.vue index 6ef04b7c..a494ba8a 100644 --- a/app/javascript/photos/show.vue +++ b/app/javascript/photos/show.vue @@ -13,8 +13,8 @@ :id="photo.id" :title="photoTitle()" @update-title="updatePhotoTitle" - @enable-keyboard-shortcuts="enableKeyboardShortcuts" - @disable-keyboard-shortcuts="disableKeyboardShortcuts" + @enable-keyboard-shortcuts="enableNavigationShortcuts" + @disable-keyboard-shortcuts="disableNavigationShortcuts" />

{ - enableKeyboardShortcuts() + enableNavigationShortcuts() }) onBeforeUnmount(() => { - disableKeyboardShortcuts() + disableNavigationShortcuts() }) - const enableKeyboardShortcuts = () => { + const enableNavigationShortcuts = () => { document.addEventListener('keydown', handleKeyDown) } - const disableKeyboardShortcuts = () => { + const disableNavigationShortcuts = () => { document.removeEventListener('keydown', handleKeyDown) } const handleKeyDown = (event) => { if (event.key === 'ArrowLeft') { - if (photo.value.previousPhoto) { - router.push({ name: 'photos-show', params: { id: photo.value.previousPhoto.id } }) - } + navigateToPreviousPhoto() } else if (event.key === 'ArrowRight') { - if (photo.value.nextPhoto) { - router.push({ name: 'photos-show', params: { id: photo.value.nextPhoto.id } }) - } + navigateToNextPhoto() + } + } + + const navigateToNextPhoto = () => { + if (photo.value.nextPhoto) { + router.push({ name: 'photos-show', params: { id: photo.value.nextPhoto.id } }) + } + } + + const navigateToPreviousPhoto = () => { + if (photo.value.previousPhoto) { + router.push({ name: 'photos-show', params: { id: photo.value.previousPhoto.id } }) } } From bf6ca77479f0e32b29b7594e60fa12effa96137c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Rusiczki?= Date: Tue, 25 Apr 2023 21:47:07 +0300 Subject: [PATCH 3/3] RSS feeds with autodiscovery --- app/controllers/albums_controller.rb | 7 +++++++ app/controllers/photos_controller.rb | 7 +++++++ app/views/albums/feed.xml.builder | 21 +++++++++++++++++++++ app/views/albums/index.html.erb | 1 + app/views/homepage/index.html.erb | 7 +++++++ app/views/layouts/application.html.erb | 2 ++ app/views/photos/feed.xml.builder | 25 +++++++++++++++++++++++++ app/views/photos/index.html.erb | 1 + config/routes.rb | 5 ++++- 9 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 app/views/albums/feed.xml.builder create mode 100644 app/views/photos/feed.xml.builder diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 51a6ffee..c82b613a 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -14,4 +14,11 @@ def show @album = Album.includes(:albums_photos).friendly.find(params[:id]) @pagy, @photos = pagy(@album.photos.order(:ordering)) end + + def feed + @albums = Album.all.order(created_at: :desc).limit(30) + respond_to do |format| + format.xml + end + end end diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 78f64d4e..1a1843a2 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -28,6 +28,13 @@ def upload @photo = Photo.new end + def feed + @photos = Photo.all.order(imported_at: :desc).limit(30) + respond_to do |format| + format.xml + end + end + def create @photo = Photo.new(photo_params) authorize @photo diff --git a/app/views/albums/feed.xml.builder b/app/views/albums/feed.xml.builder new file mode 100644 index 00000000..c4dba253 --- /dev/null +++ b/app/views/albums/feed.xml.builder @@ -0,0 +1,21 @@ +xml.instruct! :xml, version: "1.0" +xml.rss version: "2.0" do + xml.channel do + xml.title "Photonia - Albums" + xml.description "Albums by Janos Rusiczki" + xml.link albums_url + + @albums.each do |album| + xml.item do + xml.title album.title + xml.description album.description + xml.pubDate album.created_at.to_s(:rfc822) + xml.link album_url(album) + xml.guid album_url(album) + if cover_image = album&.photos&.first&.image(:medium_intelligent).presence || album&.photos&.first&.image(:medium_square) + xml.enclosure url: cover_image.url, type: cover_image.mime_type, length: cover_image.size + end + end + end + end +end diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index eda50b0b..01d9347b 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -1,4 +1,5 @@ <% content_for(:page_title, 'Albums' + (@pagy.page == 1 ? '' : " - Page #{@pagy.page}")) %> +<% content_for(:autodiscovery_link, auto_discovery_link_tag(:rss, feed_albums_url(format: :xml), title: 'Photonia Albums RSS')) %>

Albums


diff --git a/app/views/homepage/index.html.erb b/app/views/homepage/index.html.erb index 13e6c06a..7be445cb 100644 --- a/app/views/homepage/index.html.erb +++ b/app/views/homepage/index.html.erb @@ -1,3 +1,10 @@ +<% + content_for( + :autodiscovery_link, + auto_discovery_link_tag(:rss, feed_photos_url(format: :xml), title: 'Photonia Photos RSS') + "\n " + + auto_discovery_link_tag(:rss, feed_albums_url(format: :xml), title: 'Photonia Albums RSS') + ) +%>

Latest photo

diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 8e400a6e..8e084a89 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,6 +13,8 @@ <%= ENV['PHOTONIA_TRACKING_CODE']&.html_safe %> + <%= yield(:autodiscovery_link) %> + <%= javascript_tag nonce: true do %> window.configuration_json = <%= @configuration_json.html_safe %> window.gql_queries = <%= @gql_queries.html_safe %> diff --git a/app/views/photos/feed.xml.builder b/app/views/photos/feed.xml.builder new file mode 100644 index 00000000..66b1353a --- /dev/null +++ b/app/views/photos/feed.xml.builder @@ -0,0 +1,25 @@ +xml.instruct! :xml, version: "1.0" +xml.rss version: "2.0", "xmlns:media": "http://search.yahoo.com/mrss/" do + xml.channel do + xml.title "Photonia - Photos" + xml.description "Photos by Janos Rusiczki" + xml.link photos_url + + @photos.each do |photo| + next unless medium_image = photo.image(:medium) + thumbnail_image = photo.image(:thumbnail_intelligent).presence || photo.image(:thumbnail_square) + xml.item do + xml.title photo.name + xml.description photo.description + xml.pubDate photo.created_at.to_s(:rfc822) + xml.link photo_url(photo) + xml.guid photo_url(photo) + xml.media :content, url: medium_image.url, type: medium_image.mime_type, width: medium_image.width, height: medium_image.height + xml.media title: photo.name + xml.media description: photo.description + xml.media :thumbnail, url: thumbnail_image.url, width: thumbnail_image.width, height: thumbnail_image.height + xml.media :credit, role: "photographer", content: "Janos Rusiczki" + end + end + end +end diff --git a/app/views/photos/index.html.erb b/app/views/photos/index.html.erb index 9abc255f..0ecb3054 100644 --- a/app/views/photos/index.html.erb +++ b/app/views/photos/index.html.erb @@ -1,4 +1,5 @@ <% content_for(:page_title, 'Photos' + (@pagy.page == 1 ? '' : " - Page #{@pagy.page}")) %> +<% content_for(:autodiscovery_link, auto_discovery_link_tag(:rss, feed_photos_url(format: :xml), title: 'Photonia Photos RSS')) %>

Photos


diff --git a/config/routes.rb b/config/routes.rb index 6018e9de..67bd70fb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,9 +10,12 @@ resources :photos, except: %i[new] do get :upload, on: :collection + get :feed, on: :collection, format: :xml end resources :tags, only: %i[index show] - resources :albums, only: %i[index show] + resources :albums, only: %i[index show] do + get :feed, on: :collection, format: :xml + end post '/graphql', to: 'graphql#execute'