From 6688dfe09b22a789cda56a19c7abeef583592209 Mon Sep 17 00:00:00 2001
From: Antonio Ospite <ao2@ao2.it>
Date: Sun, 15 May 2016 15:34:13 +0200
Subject: [PATCH 1/1] rss_converter_facebook.com.xsl: fix the permalink

Use the page id and the story id to build a more robust permalink URL.
---
 rss_converter_facebook.com.xsl | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/rss_converter_facebook.com.xsl b/rss_converter_facebook.com.xsl
index 9fbc187..347f1e4 100644
--- a/rss_converter_facebook.com.xsl
+++ b/rss_converter_facebook.com.xsl
@@ -42,9 +42,23 @@
         <xsl:text>https://facebook.com</xsl:text>
     </xsl:variable>
 
+    <!--
+         Extract the page id from an element like:
+        <meta property="al:android:url" content="fb://page/793837197390834">
+
+        The page id will be used to build the permalink.
+    -->
+    <xsl:variable
+        name="page-id"
+        select="substring-after(//meta[@property='al:android:url']/@content, 'fb://page/')"/>
+
     <xsl:template match="//div[contains(@class, 'userContentWrapper')]">
+        <xsl:variable name="story-id" select=".//input[@name='ft_ent_identifier']/@value"/>
         <xsl:variable name="item-content" select=".//div[contains(@class, 'userContent')]"/>
-        <xsl:variable name="item-permalink" select="concat($BaseURL, .//a[@target='']/@href)"/>
+        <xsl:variable
+            name="item-permalink"
+            select="concat($BaseURL, '/permalink.php?id=', $page-id, '&amp;story_fbid=', $story-id)"/>
+
         <item>
             <title>
                 <xsl:variable name="item-title" select="$item-content/p"/>
-- 
2.1.4