Niedzielski has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/323087

Change subject: WIP: Update: add news headline topic property
......................................................................

WIP: Update: add news headline topic property

todo: tests :]

Bug: T148444
Change-Id: I6cd0b7081a9ba06a58732efba7922029f66c84cf
---
M etc/feed/news-sites.js
M lib/feed/news.js
M spec.yaml
M test/features/news/news.js
4 files changed, 52 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/87/323087/1

diff --git a/etc/feed/news-sites.js b/etc/feed/news-sites.js
index 9ac4505..6e8e582 100644
--- a/etc/feed/news-sites.js
+++ b/etc/feed/news-sites.js
@@ -6,10 +6,12 @@
     /**
      * @param {!string} title
      * @param {!string} headlineSelector
+     * @param {!string} topicAnchorSelector
      */
-    constructor(title, headlineSelector) {
+    constructor(title, headlineSelector, topicAnchorSelector) {
         this._title = title;
         this._headlineSelector = headlineSelector;
+        this._topicAnchorSelector = topicAnchorSelector;
     }
 
     /**
@@ -27,27 +29,50 @@
     headlineSelector() {
         return this._headlineSelector;
     }
+
+    /**
+     * @return {!string} Query selector for news headline subject links; this
+     *                   selector should be used on a headline element
+     */
+    topicAnchorSelector() {
+        return this._topicAnchorSelector;
+    }
 }
+
+const TOPIC_SELECTOR_LINK = 'a:nth-of-type(1)';
+const TOPIC_SELECTOR_BOLD_LINK = 'b:nth-of-type(1) a';
 
 /**
  * @type {{Object.<string, NewsSite>}} A map of Wikipedia site languages codes
  *                                     to NewsSites
  */
 module.exports = {
-    en: new NewsSite('Template:In_the_news', 'ul[id^=mw] li'),
-    da: new NewsSite('Skabelon:Forside_aktuelle_begivenheder', 'div > li'),
-    de: new NewsSite('Wikipedia:Hauptseite/Aktuelles', 'li'),
-    el: new NewsSite('Πύλη:Τρέχοντα_γεγονότα/Επικεφαλίδες', 'li'),
+    en: new NewsSite('Template:In_the_news', 'ul[id^=mw] li',
+    TOPIC_SELECTOR_BOLD_LINK),
+    da: new NewsSite('Skabelon:Forside_aktuelle_begivenheder', 'div > li',
+    TOPIC_SELECTOR_BOLD_LINK),
+    de: new NewsSite('Wikipedia:Hauptseite/Aktuelles', 'li',
+    TOPIC_SELECTOR_LINK),
+    el: new NewsSite('Πύλη:Τρέχοντα_γεγονότα/Επικεφαλίδες', 'li',
+    TOPIC_SELECTOR_LINK),
     es: new NewsSite('Portal:Actualidad',
-        'table:not(.infobox) > tbody > tr > td > dl + ul:nth-of-type(1) > li'),
-    fi: new NewsSite('Malline:Uutisissa', 'body > ul > li'),
-    fr: new NewsSite('Modèle:Accueil_actualité', 'div ul[id^=mw] > li'),
-    he: new NewsSite('תבנית:חדשות_ואקטואליה', 'body > ul > li'),
-    ko: new NewsSite('틀:새로_들어온_소식', 'body > ul > li'),
-    no: new NewsSite('Mal:Aktuelt', 'ul > li'),
-    pl: new NewsSite('Szablon:Aktualności', 'ul:last-of-type > li'),
-    pt: new NewsSite('Portal:Eventos_atuais', 'div > ul > li'),
-    ru: new NewsSite('Шаблон:Актуальные_события', 'body > ul > li'),
-    sv: new NewsSite('Portal:Huvudsida/Aktuella händelser', 'body > ul > li'),
-    vi: new NewsSite('Bản_mẫu:Tin_tức', 'ul > li')
+        'table:not(.infobox) > tbody > tr > td > dl + ul:nth-of-type(1) > li',
+        TOPIC_SELECTOR_LINK),
+    fi: new NewsSite('Malline:Uutisissa', 'body > ul > li',
+    TOPIC_SELECTOR_BOLD_LINK),
+    fr: new NewsSite('Modèle:Accueil_actualité', 'div ul[id^=mw] > li',
+    TOPIC_SELECTOR_BOLD_LINK),
+    he: new NewsSite('תבנית:חדשות_ואקטואליה', 'body > ul > li',
+    TOPIC_SELECTOR_LINK),
+    ko: new NewsSite('틀:새로_들어온_소식', 'body > ul > li', 
TOPIC_SELECTOR_BOLD_LINK),
+    no: new NewsSite('Mal:Aktuelt', 'ul > li', TOPIC_SELECTOR_BOLD_LINK),
+    pl: new NewsSite('Szablon:Aktualności', 'ul:last-of-type > li',
+    TOPIC_SELECTOR_BOLD_LINK),
+    pt: new NewsSite('Portal:Eventos_atuais', 'div > ul > li',
+    TOPIC_SELECTOR_BOLD_LINK),
+    ru: new NewsSite('Шаблон:Актуальные_события', 'body > ul > li',
+    TOPIC_SELECTOR_BOLD_LINK),
+    sv: new NewsSite('Portal:Huvudsida/Aktuella händelser', 'body > ul > li',
+    TOPIC_SELECTOR_BOLD_LINK),
+    vi: new NewsSite('Bản_mẫu:Tin_tức', 'ul > li', TOPIC_SELECTOR_BOLD_LINK)
 };
\ No newline at end of file
diff --git a/lib/feed/news.js b/lib/feed/news.js
index 83fc8aa..e5e4221 100644
--- a/lib/feed/news.js
+++ b/lib/feed/news.js
@@ -15,7 +15,7 @@
     return href;
 }
 
-function constructStory(restbase_tpl, domain, storyHtml) {
+function constructStory(restbase_tpl, domain, lang, storyHtml) {
     const story = { links: [] };
     const linkTitles = [];
 
@@ -34,6 +34,10 @@
     });
 
     story.story = storyHtml.innerHTML;
+    const topicAnchor = 
storyHtml.querySelector(NEWS_TEMPLATES[lang].topicAnchorSelector());
+    if (topicAnchor) {
+        story.title = topicAnchor.getAttribute('href');
+    }
     return story;
 }
 
@@ -64,7 +68,7 @@
         };
 
         Array.prototype.forEach.call(headlines, function(storyHtml) {
-            result.payload.push(constructStory(app.restbase_tpl, 
req.params.domain, storyHtml));
+            result.payload.push(constructStory(app.restbase_tpl, 
req.params.domain, lang, storyHtml));
         });
 
         return result;
diff --git a/spec.yaml b/spec.yaml
index a5351b9..65f9697 100644
--- a/spec.yaml
+++ b/spec.yaml
@@ -682,6 +682,9 @@
       story:
         type: string
         description: A cover story for the news item
+      title:
+        type: string
+        description: The unnormalized topic title of the news item; may 
contain a URL fragment
       links:
         type: array
         description: A collection of articles related to the news item
diff --git a/test/features/news/news.js b/test/features/news/news.js
index a8cc1bd..ce4ec18 100644
--- a/test/features/news/news.js
+++ b/test/features/news/news.js
@@ -22,6 +22,7 @@
 
 const testStoryObj = {
     story: '<!--July 22--> In <a rel="mw:WikiLink" href="./Sport_of_athletics" 
title="Sport of athletics" id="mwCQ">athletics</a>, American sprinter <a 
rel="mw:WikiLink" href="./Kendra_Harrison" title="Kendra Harrison" 
id="mwCg">Kendra Harrison</a> breaks the <a rel="mw:WikiLink" 
href="./Women\'s_100_metres_hurdles_world_record_progression" title="Women\'s 
100 metres hurdles world record progression" id="mwCw">28-year-old</a> <a 
rel="mw:WikiLink" href="./100_metres_hurdles" title="100 metres hurdles" 
id="mwDA">100 metres hurdles</a> <b id="mwDQ"><a rel="mw:WikiLink" 
href="./100_metres_hurdles#Top_25_fastest_athletes" title="100 metres hurdles" 
id="mwDg">world record</a></b> at the <a rel="mw:WikiLink" 
href="./London_Grand_Prix" title="London Grand Prix" id="mwDw">London Grand 
Prix</a>.',
+    title: './100_metres_hurdles#Top_25_fastest_athletes',
     links: [
         { $merge: [ mUtil.getRbPageSummaryUrl(mock_restbase_tpl, 
'en.wikipedia.org', 'Sport_of_athletics') ] },
         { $merge: [ mUtil.getRbPageSummaryUrl(mock_restbase_tpl, 
'en.wikipedia.org', 'Kendra_Harrison') ] },
@@ -81,7 +82,7 @@
 
     it('News story constructed correctly (duplicate titles handled 
correctly)', function() {
         const html = 
domino.createDocument(testStoryHtml).getElementsByTagName('li')[0];
-        const story = news.constructStory(mock_restbase_tpl, 
'en.wikipedia.org', html);
+        const story = news.constructStory(mock_restbase_tpl, 
'en.wikipedia.org', 'en', html);
         assert.deepEqual(story, testStoryObj);
     });
 });

-- 
To view, visit https://gerrit.wikimedia.org/r/323087
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6cd0b7081a9ba06a58732efba7922029f66c84cf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to