Interplanetary File System - Simple IPFS Blog Using XSLT

There is a problem: A site in IPFS does not have the ability to use server-side scripts to form a page. If you use page generation before loading, adding a new menu item to each page will change the hash of these pages. So the whole assembly of pages must be done by the browser.


Usually form the content of pages using JavaScript. This is a familiar technology, but it has its drawbacks.


I will use XSLT. This is an ancient template technology that has long been built into browsers but few use it. Perhaps because templates make you write a lot of text due to confusion with namespaces and a lot of mistakes without a clear explanation. Also, despite the fact that there are already XSLT 3.0 in browsers, only XSLT 1.0 is still available.


XSLT works like this:


  1. A user opens an XML document in a browser.
  2. In the XML header, the document contains a link to the XSLT template.
    <?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
  3. A template in a browser based on an XML document and other data forms an xHTML document.
  4. The browser displays the resulting xHTML document.

By linking multiple pages to one template, you can change the displayed xHTML document without changing the XML documents. Thus, when changing the design, the hash of XML documents will not change, which means that their old copies will be sources for new ones in IPFS.


. XML .


image



XML . XML HTML:


  1. .
    <br />.
  2. . .
    <>
        < />
        <- />
        <-- />
    </>
  3. .
    <>
         
    </>

.xml


.


XML - :
: ' .xml'


<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
<>
    <></>
    <>
        <></>
    </>
</>
<!--         -->

. . meta description. .


xHTML ( HTML ) .


:


: 'Lorem Ipsum.xml'
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
<>
    <>Lorem Ipsum</>
    <>
<h1>Lorem ipsum dolor sit amet</h1>

<>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras feugiat orci non orci tincidunt molestie. Donec eget porta metus. Aenean malesuada nunc lacus, a sollicitudin neque fermentum eu. <b style="color: green">Vestibulum egestas viverra urna</b>, sit amet mollis ipsum commodo imperdiet. Quisque sit amet est eu nibh commodo pharetra.</> Donec fermentum nisi nec lorem auctor imperdiet. Morbi ultricies at magna ullamcorper malesuada. In eget arcu dapibus, vehicula nunc vel, convallis erat. Cras accumsan lacus vel tellus gravida, eu gravida turpis congue. In ultrices pellentesque odio at hendrerit.

<h1>Cras nec lorem facilisis</h1>

Cras nec lorem facilisis justo porttitor scelerisque id id ipsum. Duis mattis, sem eu sollicitudin pharetra, diam augue ullamcorper nisl, id dictum turpis ex in nisl. Aliquam venenatis egestas urna eget porttitor. Suspendisse potenti. Curabitur fermentum fermentum nulla, a lobortis ipsum laoreet eget. Duis finibus lacus id tempor elementum. <i>Interdum et malesuada fames ac ante ipsum primis in faucibus</i>. Curabitur tempus eget turpis ut tincidunt. In quis massa et risus tempor luctus quis eu enim. Duis finibus sem sit amet elit scelerisque molestie. Suspendisse laoreet, leo ut accumsan dapibus, nisi tellus dignissim lorem, eu auctor tellus diam vel nisi. Donec sem tortor, suscipit a leo maximus, aliquet dapibus nisl. Integer sodales, dui ut vulputate pharetra, ipsum neque tempor ipsum, sed porta tortor quam a nisl.

Sed consequat purus sed porttitor pulvinar. Mauris sollicitudin non sem a malesuada. Vestibulum non velit finibus, elementum purus nec, aliquam lacus. Etiam leo enim, venenatis id luctus ut, ornare sit amet ex. Nunc vel fringilla ante. Cras lobortis scelerisque pulvinar. Ut lectus augue, viverra quis molestie eu, maximus nec leo. <u>Sed facilisis odio ut malesuada mollis</u>. Pellentesque enim lacus, luctus nec velit quis, scelerisque tincidunt magna. Proin laoreet, erat eget porttitor bibendum, odio augue suscipit purus, id commodo magna nibh sed est. Ut dignissim aliquet sem, id suscipit sapien mollis volutpat. Vivamus ac fringilla est, at sagittis diam.
    </>
</>

.xhtml


xHTML XSLT . . XSLT .


xHTML XML.


: 'xhtml/.xhtml'


<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <!--   <>     title    -->
        <title class="">   XML</title>
        <meta  class=""/>
        <!--       HTML -->
        <style>
            /*   xHTML    */

            .{
                white-space: pre-wrap;
            }

            /*       */

              . h1, . h2
            , . h3, . h4
            , . h5, . h6 {
                display: inline;
            }
        </style>
    </head>
    <body>
        <!--           -->
        <ul   class="" />
        <h1   class="" />
        <span class=""> <b style="color: red"><![CDATA[<></>]]></b>   .  .</span>
    </body>
</html>

.xslt


(XML xHTML) XSLT.


'.xhtml' XML. XML xHTML.


: 'xslt/.xslt'


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  version="1.0"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <!--
                '.xslt'
              
        Chrome     URL   URL
    -->
    <xsl:include href="%D0%BD%D0%B0%D0%B2%D0%B8%D0%B3%D0%B0%D1%86%D0%B8%D1%8F.xslt" />

    <!--      xHTML     XML -->
    <xsl:output method="xml" encoding="UTF-8"/>

    <!--        -->
    <xsl:variable name="" select="" />

    <!--     '.xhtml' -->
    <xsl:template match="/">
        <!-- mode            -->
        <xsl:apply-templates mode="xhtml" select="document('../xhtml/%D0%B7%D0%B0%D0%BF%D0%B8%D1%81%D1%8C.xhtml')" />
    </xsl:template>

    <!--        -->
    <xsl:template mode="xhtml" match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates mode="xhtml" select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <!--         '.xhtml' -->

    <!--   match    Firefox -->

    <!--    ''     '' -->
    <xsl:template mode="xhtml" match="*[contains(@class, '')]">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates mode="xml" select="$////node()" />
        </xsl:copy>
    </xsl:template>

    <!--   meta    '' -->
    <xsl:template mode="xhtml" match="xhtml:meta[contains(@class, '')]">
        <meta name="description" content="{$///}" />
    </xsl:template>

    <!--       -->
    <xsl:template mode="xhtml" match="*[contains(@class, '')]">
        <!--       '.xsl' -->
        <xsl:call-template name="" />
    </xsl:template>

    <!--    ''     '' -->
    <xsl:template mode="xhtml" match="*[contains(@class, '')]">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:value-of select="$/" />
        </xsl:copy>
    </xsl:template>

    <!--    ''     '' -->
    <xsl:template mode="xhtml" match="*[contains(@class, '')]">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates mode="xml" select="$//node()" />
        </xsl:copy>
    </xsl:template>

    <!-- 
              xml 

              
        (   svg )  
     -->
    <xsl:template mode="xml" match="*[namespace-uri()]|@*">
        <xsl:copy>
            <xsl:apply-templates mode="xml" select="node()|@*" />
        </xsl:copy>
    </xsl:template>

    <!--       -->
    <xsl:template mode="xml" match="*">
        <!--
                 .    
                 
        -->
        <xsl:element name="{name()}">
            <xsl:apply-templates mode="xml" select="node()|@*" />
        </xsl:element>
    </xsl:template>

    <!--    ''    -->
    <xsl:template mode="xml" match="">
        <xsl:apply-templates mode="xml" select="node()|@*" />
    </xsl:template>

    <!--      xHTML  --> 
    <xsl:template mode="xml" match="h1|h2|h3|h4|h5">
        <!-- 
            h1       '' 
               xHTML  
        -->
        <xsl:element name="h{substring(name(), 2, 1) + 1}">
            <!--          id     -->
            <xsl:attribute name="id">
                <xsl:value-of select="." />
            </xsl:attribute>
            <xsl:apply-templates mode="xml" select="node()|@*" />
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>


. .


.xml


XML :


: '.xml'


<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
<>
    <> </>
</>
<!--         -->

'' xml .


:


<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
<>
    <>Lorem Ipsum 1</>
    <>Lorem Ipsum 2</>
</>


'.xml' xHTML .


: 'xslt/.xslt'


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  version="1.0"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <!--      '.xsl' -->
    <xsl:template name="">
        <ul>
            <!--   -->
            <xsl:copy-of select="@*" />

            <!--     '.xml'   -->
            <xsl:apply-templates mode="" select="document('../%D0%B6%D1%83%D1%80%D0%BD%D0%B0%D0%BB.xml')//" />
        </ul>
    </xsl:template>

    <!--       -->
    <xsl:template mode="" match="">
        <li>
            <a href="{text()}.xml">
                <xsl:value-of select="text()" />
            </a>
        </li>
    </xsl:template>

</xsl:stylesheet>

.



.


index.html


IPFS index.html. XML .


'.xml'.


: 'index.html'


<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <!--     '.xml' -->
        <!-- Firefox      url   -->
        <meta http-equiv="refresh" content="0; url=%D0%B6%D1%83%D1%80%D0%BD%D0%B0%D0%BB.xml" />
    </head>
    <body>
        <!--        -->
         :
        "<a class="" href=".xml"></a>"
    </body>
</html>

HTML . XML HTML . .


.xslt


'.xml' '.xslt'. '.xml' 'index.html' .


: 'xslt/.xslt'


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  version="1.0"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" encoding="UTF-8"/>

    <xsl:variable name="" select="//text()" />

    <xsl:template match="/">
        <!--       -->
        <xsl:apply-templates mode="html" select="document('../index.html')" />
    </xsl:template>

    <!--     -->
    <xsl:template mode="html" match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates mode="html" select="node()|@*" />
        </xsl:copy>
    </xsl:template>

    <!--    -->

    <!--     -->
    <xsl:template mode="html" match="xhtml:meta[@http-equiv='refresh']">
        <!--
             
             1.   URL
                      URL
        -->
        <base href="{$}.xml" />

        <!-- 2.   -->
        <meta http-equiv="refresh" content="0; url=#" />
    </xsl:template>

    <!--         -->
    <xsl:template mode="html" match="xhtml:a[@class='']">
        <a href="" class="{@class}">
            <xsl:value-of select="$" />
        </a>
    </xsl:template>

</xsl:stylesheet>

'.xslt' .



  1. '.xml' :


    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
    <>
        <>  </>
    </>

  2. ' .xml' ' .xml'


  3. :


    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
    <>
        <>  </>
        <>
       .
        </>
    </>


.



IPFS .


Firefox


  1. about:config security.fileuri.strict_origin_policy false

Chrome


  1. --allow-file-access-from-files

IPFS


.


ID


.


ipfs key gen -t rsa blog

ID



  1. ipfs


    ipfs add -r -s rabin --inline --raw-leaves --fscache < >

    -r โ€”
    -s rabin โ€” jpeg, mp3 .
    --inline โ€” .
    --raw-leaves โ€” --nocopy .
    --fscache โ€” .


  2. ID .


    ipfs name publish -k blog <>



:


http://127.0.0.1:8080/ipfs/<>
http://127.0.0.1:8080/ipns/<id >

:


http://gateway.ipfs.io/ipfs/<>
http://gateway.ipfs.io/ipns/<id >

. ID .


.



Naturally, the design and functionality of this blog can and should be developed to meet the needs of the user. I set some base from which to develop further.


References


Good reference on XSLT
GitHub code ( snapshot )


All Articles