MITLibraries / MITLibraries-news

A Wordpress child theme for the news site, descending from MITLibraries-parent
GNU General Public License v3.0
2 stars 3 forks source link

Add custom fields to RSS #36

Open frrrances opened 8 years ago

frrrances commented 8 years ago

The current news and events RSS doesn't include custom fields, especially the subtitle and event date/time ones. We need to add those and any other custom fields we want into the RSS feed template.

PBruk commented 8 years ago

Am not 100% sure about this, will double-check with @matt-bernhardt, next week.

matt-bernhardt commented 8 years ago

To make sure I understand the scope of this, we're talking about the RSS feeds that are specifically provided by the News theme, right? So those listed here: http://libguides.mit.edu/rss/mit-feeds

http://libraries.mit.edu/news/category/1/feed/

Specifically, we're looking to add custom fields to an entry that currently looks like this:

<item>
    <title>Congratulations, Class of 2016</title>
    <link>http://libraries.mit.edu/news/congratulations-class/22181/</link>
    <pubDate>Tue, 31 May 2016 13:42:33 +0000</pubDate>
    <dc:creator><![CDATA[Brigham Fay]]></dc:creator>
    <category><![CDATA[All news]]></category>
    <guid isPermaLink="false">http://libraries.mit.edu/news/?p=22181</guid>
    <description>
        <![CDATA[
            Finals are over, theses are submitted, your library books have been returned (ahem) — it&#8217;s time to celebrate! Congratulations and best wishes from all of us at the MIT Libraries. Before you leave, we want to let you know some of the ways you can continue to benefit, and stay in touch, even after you leave campus. [&#8230;]
        ]]>
    </description>
    <content:encoded>
        <![CDATA[
            <div id="attachment_22182" style="width: 310px" class="wp-caption alignright"><a href="http://libraries.mit.edu/news/files/2016/05/commencement.jpg" rel="attachment wp-att-22182"><img class="size-medium wp-image-22182" src="http://libraries.mit.edu/news/files/2016/05/commencement-300x200.jpg" alt="Photo: Dominick Reuter" width="300" height="200" srcset="https://libraries.mit.edu/news/files/2016/05/commencement-300x200.jpg 300w, https://libraries.mit.edu/news/files/2016/05/commencement-768x512.jpg 768w, https://libraries.mit.edu/news/files/2016/05/commencement-624x416.jpg 624w, https://libraries.mit.edu/news/files/2016/05/commencement.jpg 948w" sizes="(max-width: 300px) 100vw, 300px" /></a><p class="wp-caption-text">Photo: Dominick Reuter</p></div>
            <p>Finals are over, theses are submitted, your library books have been <a href="http://libguides.mit.edu/c.php?g=176140&amp;p=1160492">returned</a> (<a href="http://libraries.mit.edu/news/avoid-fines-summer/22267/">ahem</a>) — it&#8217;s time to celebrate! Congratulations and best wishes from all of us at the MIT Libraries.</p>
            <p>Before you leave, we want to let you know some of the ways you can continue to benefit, and stay in touch, even after you leave campus. As an MIT alumnus/a, you can:</p>
            <ul>
            <li>Receive a 20% discount on all <a href="https://mitpress.mit.edu">MIT Press</a> titles with the code MITALUM</li>
            <li>Apply for a <a href="http://libraries.mit.edu/docs/p-cards/">borrowing card</a> and access scholarly journals online through your <a href="https://alumsso.mit.edu/cas/login?service=https%3A%2F%2Falum.mit.edu%2Fcas%3Fdestination%3D/benefits/AlumniBenefits/e-journal">MIT Alumni Association Infinite Connection</a> account</li>
            <li>Add your <a href="http://libguides.mit.edu/mit-thesis-faq/add-your-thesis">thesis</a> to the Space@MIT repository</li>
            <li>Follow the Libraries on <a href="http://connect.mit.edu/profile/mit-libraries">social media</a> for the latest news from across the Institute, snapshots of campus life, and highlights from our unique collections</li>
            <li><a href="http://libraries.mit.edu/news/subscribe/">Subscribe</a> to our e-newsletter for the latest updates on our efforts in <a href="http://libraries.mit.edu/news/category/scholarly-communication/">Open Access</a>, the <a href="https://future-of-libraries.mit.edu">Future of Libraries task force</a>, and more</li>
            </ul>
            <p>Staying at MIT for graduate study? Don&#8217;t forget about the many valuable services and tools the Libraries offer to the MIT community:</p>
            <ul>
            <li><a href="http://libraries.mit.edu/data-management/services/">Data management services</a></li>
            <li><a href="http://libguides.mit.edu/publishing">Help with getting published</a></li>
            <li><a href="http://libguides.mit.edu/manage-info">Citation and content management tools</a></li>
            <li><a href="http://libraries.mit.edu/research-support/productivity-tools/">Productivity tools</a></li>
            </ul>
            <p>Wherever life takes you next, we hope you will always consider the Libraries your home!</p>
            <p>&nbsp;</p>
        ]]>
    </content:encoded>
</item>
matt-bernhardt commented 8 years ago

There's a distinction to be made about whether we need the additional information added to the item content (either content:encoded or description tags), or to the item metadata.

Adding more information to the item content should be relatively straightforward, we just edit the relevant template. Adding things to the metadata is probably possible, but it isn't simply adding a subtitle field.

The RSS spec for item elements ( https://validator.w3.org/feed/docs/rss2.html#hrelementsOfLtitemgt ) is very specific about allowing only certain tags:

We've managed to add some additional tags (like dc:creator) by adding in the Dublin Core schema, which should also allow us to add an Event type via dc:type if I read http://dublincore.org/documents/2012/06/14/dcmi-terms/?v=elements#dcmitype-Event correctly.

The best way forward is probably to assemble the full list of fields we want to add, and see whether the schema we're already using make those available. Anything still missing will need to some research about how best to implement.

frrrances commented 8 years ago

Actually, what I would like as an MVP at this point is to add the subtitle to the description area, and if it is an event, the date that the event will take place. (We may tweak more later but this is key information that is currently missing.) I am assuming this is via editing the wordpress RSS template to put that info into the description area like so:

<title>[Wordpress post title]</title>
<link>[Wordpress post link]</link>
<pubDate>[Wordpress post publish date]</pubDate>
<dc:creator><![CDATA[Wordpress Author]]></dc:creator>
<category><![CDATA[Wordpress category]]></category>
<guid isPermaLink="false">[Wordpress permalink]</guid>
<description>
[Wordpress subtitle]
<if event>Event date and time: [Wordpress event date and time]</ifevent>
[Wordpress summary]
</description>
... (the rest of the feed)

which becomes:

Can Computers be Feminist? Procedural Politics and Computational Creativity May 26, 2016 at 9:00 AM A brown bag discussion with Gillian Smith Event date and time: June 14, 2016, 12-1pm (ET) Join the Program on Information Science for a brown bag talk, Can Computers be Feminist? Procedural Politics and Computational Creativity. Discussant Gillian Smith will examine how computers are increasingly taking on the role of a creator — making content for games, participating on Twitter, and generating paintings and sculptures. These computationally creative systems embody formal models […]

matt-bernhardt commented 8 years ago

Okay, great - if we're adding this to the content/description elements, then this is pretty straightforward. @PBruk I would recommend looking over https://codex.wordpress.org/Customizing_Feeds for information on the templates to look for / create. I'm not sure any of these exist in this theme currently.