Interplanetares Dateisystem - Einfaches IPFS-Blog mit XSLT

Es gibt ein Problem: Eine Site in IPFS kann keine serverseitigen Skripts zum Erstellen einer Seite verwenden. Wenn Sie die Seitengenerierung vor dem Laden verwenden und dann jeder Seite einen neuen Menüpunkt hinzufügen, ändern wir den Hash dieser Seiten. Die gesamte Zusammenstellung der Seiten muss also vom Browser durchgeführt werden.


Normalerweise bilden Sie den Inhalt von Seiten mit JavaScript. Dies ist eine bekannte Technologie, die jedoch ihre Nachteile hat.


Ich werde XSLT verwenden. Dies ist eine alte Vorlagentechnologie, die seit langem in Browser integriert ist, aber nur von wenigen verwendet wird. Vielleicht, weil Sie aufgrund von Vorlagen aufgrund von Verwechslungen mit Namespaces und vielen Fehlern ohne klare Erklärung viel Text schreiben müssen. Obwohl in Browsern bereits XSLT 3.0 vorhanden ist, ist nur noch XSLT 1.0 verfügbar.


XSLT funktioniert folgendermaßen:


  1. Ein Benutzer öffnet ein XML-Dokument in einem Browser.
  2. Im XML-Header enthält das Dokument einen Link zur XSLT-Vorlage.
    <?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
  3. Eine Vorlage in einem Browser, die auf einem XML-Dokument und anderen Daten basiert, bildet ein xHTML-Dokument.
  4. Der Browser zeigt das resultierende xHTML-Dokument an.

Durch Verknüpfen mehrerer Seiten mit einer Vorlage können Sie das angezeigte xHTML-Dokument ändern, ohne die XML-Dokumente zu ändern. Wenn Sie das Design ändern, ändert sich der Hash von XML-Dokumenten nicht. Dies bedeutet, dass ihre alten Kopien Quellen für neue in IPFS sind.


. XML .


Bild



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 .


.



Natürlich kann und sollte das Design und die Funktionalität dieses Blogs so entwickelt werden, dass sie den Bedürfnissen des Benutzers entsprechen. Ich habe eine Basis geschaffen, von der aus ich mich weiterentwickeln kann.


Verweise


Gute Referenz zum XSLT
GitHub-Code ( Schnappschuss )


All Articles