diff --git a/app/assets/javascripts/utilities/buildArticleHTML.js b/app/assets/javascripts/utilities/buildArticleHTML.js index 51365d92d..e16cf17a5 100644 --- a/app/assets/javascripts/utilities/buildArticleHTML.js +++ b/app/assets/javascripts/utilities/buildArticleHTML.js @@ -86,6 +86,45 @@ function buildArticleHTML(article, currentUserId = null) { return parsedDocument.body.innerHTML; } + if (article && article.class_name === 'User' && article.user === undefined) { // Represents different return values for how users are fetched. + const html = ` +
+
+ + + +
+

+ ${article.name} +

+

@${article.username}

+ ${ + article.summary + ? `
${article.summary}
` + : '' + } +
+ +
+
+ `; + + const parser = new DOMParser(); + const parsedDocument = parser.parseFromString(html, 'text/html'); + parsedDocument.querySelector('img').alt = article.name; + parsedDocument.querySelector('button').dataset.info = JSON.stringify({ + id: article.id, + name: article.name, + className: 'User', + style: 'full', + }); + + return parsedDocument.body.innerHTML; + } + + if (article) { var container = document.getElementById('index-container'); diff --git a/app/javascript/packs/searchParams.js b/app/javascript/packs/searchParams.js index 6b3aa7262..e4b0cebbe 100644 --- a/app/javascript/packs/searchParams.js +++ b/app/javascript/packs/searchParams.js @@ -181,7 +181,7 @@ function search(query, filters, sortBy, sortDirection) { }); // Run Algolia code only if the ID is live. - if (document.body.dataset.algoliaId?.length > 0) { + if (document.body.dataset.algoliaId?.length > 0 && !searchParams.toString().includes('MY_POSTS')) { algoliaSearch(searchParams.toString()); return; } @@ -243,9 +243,6 @@ function algoliaSearch(searchParams) { story.class_name = paramsObj.class_name; story.id = story.objectID; // Add profile_image_90 to story object from profile image if profile_image_90 is not present - story.profile_image_90 = story.profile_image; - story.profile_image = { url: story.profile_image } - console.log(story) /* eslint-disable-line */ resultDivs.push(buildArticleHTML(story, currentUserId)); }); document.getElementById('substories').innerHTML = resultDivs.join(''); diff --git a/app/models/concerns/algolia_searchable/searchable_article.rb b/app/models/concerns/algolia_searchable/searchable_article.rb index 41e683835..bf81d76c4 100644 --- a/app/models/concerns/algolia_searchable/searchable_article.rb +++ b/app/models/concerns/algolia_searchable/searchable_article.rb @@ -7,18 +7,21 @@ module AlgoliaSearchable algoliasearch(**DEFAULT_ALGOLIA_SETTINGS, if: :indexable) do attribute :user do - { name: user.name, username: user.username, profile_image: user.profile_image_90 } + { name: user.name, + username: user.username, + profile_image: user.profile_image_90, + id: user.id, + profile_image_90: user.profile_image_90 } end attribute :title, :tag_list, :reading_time, :score, :featured, :comments_count, - :positive_reactions_count, :path, :main_image + :positive_reactions_count, :path, :main_image, :user_id add_attribute(:published_at) { published_at.to_i } + add_attribute(:readable_publish_date) { readable_publish_date } add_attribute(:timestamp) { published_at.to_i } - add_replica("Article_timestamp_desc", per_environment: true) { customRanking ["desc(timestamp)"] } add_replica("Article_timestamp_asc", per_environment: true) { customRanking ["asc(timestamp)"] } - end end diff --git a/app/models/concerns/algolia_searchable/searchable_comment.rb b/app/models/concerns/algolia_searchable/searchable_comment.rb index fd3849a81..f5cdac826 100644 --- a/app/models/concerns/algolia_searchable/searchable_comment.rb +++ b/app/models/concerns/algolia_searchable/searchable_comment.rb @@ -6,7 +6,7 @@ module AlgoliaSearchable include AlgoliaSearch algoliasearch(**DEFAULT_ALGOLIA_SETTINGS, unless: :bad_comment?) do - attribute :commentable_id, :commentable_type, :path, :parent_id + attribute :commentable_id, :commentable_type, :path, :parent_id, :title attribute :body do title end @@ -16,8 +16,15 @@ module AlgoliaSearchable end attribute :user do - { name: user.name, username: user.username, profile_image: user.profile_image_90 } + { name: user.name, + username: user.username, + profile_image: user.profile_image_90, + profile_image_90: user.profile_image_90 } end + + add_attribute(:timestamp) { created_at.to_i } + add_replica("Comment_timestamp_desc", per_environment: true) { customRanking ["desc(timestamp)"] } + add_replica("Comment_timestamp_asc", per_environment: true) { customRanking ["asc(timestamp)"] } end end diff --git a/app/models/concerns/algolia_searchable/searchable_organization.rb b/app/models/concerns/algolia_searchable/searchable_organization.rb index 4ec874117..378aec166 100644 --- a/app/models/concerns/algolia_searchable/searchable_organization.rb +++ b/app/models/concerns/algolia_searchable/searchable_organization.rb @@ -6,8 +6,12 @@ module AlgoliaSearchable algoliasearch(**DEFAULT_ALGOLIA_SETTINGS) do attribute :name, :tag_line, :summary, :slug attribute :profile_image do - profile_image_90 + { url: profile_image_90 } end + + add_attribute(:timestamp) { created_at.to_i } + add_replica("Organization_timestamp_desc", per_environment: true) { customRanking ["desc(timestamp)"] } + add_replica("Organization_timestamp_asc", per_environment: true) { customRanking ["asc(timestamp)"] } end end diff --git a/app/models/concerns/algolia_searchable/searchable_podcast_episode.rb b/app/models/concerns/algolia_searchable/searchable_podcast_episode.rb index 1b1cc1d4c..03986a425 100644 --- a/app/models/concerns/algolia_searchable/searchable_podcast_episode.rb +++ b/app/models/concerns/algolia_searchable/searchable_podcast_episode.rb @@ -13,6 +13,10 @@ module AlgoliaSearchable attribute :podcast_image do profile_image_url end + + add_attribute(:timestamp) { published_at.to_i } + add_replica("PodcastEpisode_timestamp_desc", per_environment: true) { customRanking ["desc(timestamp)"] } + add_replica("PodcastEpisode_timestamp_asc", per_environment: true) { customRanking ["asc(timestamp)"] } end end diff --git a/app/models/concerns/algolia_searchable/searchable_user.rb b/app/models/concerns/algolia_searchable/searchable_user.rb index a28ba7c5d..6557e29a0 100644 --- a/app/models/concerns/algolia_searchable/searchable_user.rb +++ b/app/models/concerns/algolia_searchable/searchable_user.rb @@ -5,9 +5,12 @@ module AlgoliaSearchable included do algoliasearch(**DEFAULT_ALGOLIA_SETTINGS, unless: :bad_actor?) do attribute :name, :username - attribute :profile_image do - profile_image_90 - end + + add_attribute(:profile_image) { { url: profile_image_90 } } + # add_attribute(:profile_image_90) { profile_image_90 } + add_attribute(:timestamp) { registered_at.to_i } + add_replica("User_timestamp_desc", per_environment: true) { customRanking ["desc(timestamp)"] } + add_replica("User_timestamp_asc", per_environment: true) { customRanking ["asc(timestamp)"] } end end diff --git a/app/views/stories/articles_search/_nav_menu.html.erb b/app/views/stories/articles_search/_nav_menu.html.erb index e4a99952d..22883d67c 100644 --- a/app/views/stories/articles_search/_nav_menu.html.erb +++ b/app/views/stories/articles_search/_nav_menu.html.erb @@ -22,4 +22,7 @@ <%= t("views.search.nav.my_posts") %> <% end %> + <% if Settings::General.display_algolia_branding %> +
  • Powered by Algolia
  • + <% end %>