From f0b2e205d9de6a3e2995f39f4e2f53c137c83042 Mon Sep 17 00:00:00 2001 From: Udo Date: Mon, 5 Jun 2023 12:23:01 +0200 Subject: [PATCH] Show hashtags in the page title --- script.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index 7b106c5..6b5c846 100644 --- a/script.js +++ b/script.js @@ -100,11 +100,22 @@ const updateWall = function(posts) { posts.forEach(post => displayPost(post)); }; +// hashtagsString returns a single string based on the given array of hashtags +const hashtagsString = function(hashtagsArray) { + return `${hashtagsArray.map(hashtag => `#${hashtag}`).join(' ')}`; +} + // updateHashtagsOnPage updates the displayed hashtags const updateHashtagsOnPage = function(hashtagsArray) { - $('#hashtag-display').text(hashtagsArray.length > 0 ? `${hashtagsArray.map(hashtag => `#${hashtag}`).join(' ')}` : 'No hashtags set'); + $('#hashtag-display').text(hashtagsArray.length > 0 ? hashtagsString(hashtagsArray) : 'No hashtags set'); }; +// updateHashtagsOnPage updates the document title by appending the given array of hashtags +const updateHashtagsInTitle = function(hashtagsArray) { + const baseTitle = document.title; + document.title = `${baseTitle} | ${hashtagsString(hashtagsArray)}`; +} + // handleHashtagDisplayClick handles the event when the hashtag display is clicked const handleHashtagDisplayClick = function(serverUrl) { $('#app-content').addClass('d-none'); @@ -179,6 +190,7 @@ $(document).ready(async function() { } updateHashtagsOnPage(hashtagsArray); + updateHashtagsInTitle(hashtagsArray); $('#hashtag-form').on('submit', function(e) { handleHashtagFormSubmit(e, hashtagsArray);