diff --git a/examples/example4/config/snippet.yaml b/examples/example4/config/snippet.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e56c1c04a3a544cc1ff33c2621f0e8bff969da26 --- /dev/null +++ b/examples/example4/config/snippet.yaml @@ -0,0 +1,11 @@ +snippet: + - source: ../template/test.html + selector: "monster-state" + destination: ../snippets/meta/container.html + attribute: + - selector: "li" + name: "data-state" + value: "monster" + replacement: + - selector: "li>span" + content: "!!!!!!!!!!!!!!!!!!" diff --git a/examples/example4/pages/en.yaml b/examples/example4/pages/en.yaml new file mode 100755 index 0000000000000000000000000000000000000000..9dc7431919c6f3e2b0a1c9c6c1498f53d3fa8d0a --- /dev/null +++ b/examples/example4/pages/en.yaml @@ -0,0 +1,73 @@ +test.html: + export: en/test.html + lang: en + title: Bad Request + meta: + author: schukai GmbH + description: The request was malformed or invalid. + images: + - id: tickyesdata-image-gi-3753669760 + source: |- + data:image/gif;base64,R0lGODdhEAAQAMwAAPj7+FmhUYjNfGuxYYDJdYTIeanOpT+DOTuANXi/bGOrWj6CONzv2sPjv2Cm + V1unU4zPgI/Sg6DJnJ3ImTh8Mtbs00aNP1CZSGy0YqLEn47RgXW8amasW7XWsmmvX2iuXiwAAAAAEAAQAAAFVyAgjmRpnihqGCkpDQ + PbGkNUOFk6DZqgHCNGg2T4QAQBoIiRSAwBE4VA4FACKgkB5NGReASFZEmxsQ0whPDi9BiACYQAInXhwOUtgCUQoORFCGt/g4QAIQA7 + alt: tick + title: "yes" + anchors: + - id: mmmm + href: mmmm + hreflang: "" + title: "" + - id: yes-a-html + href: /a.html + hreflang: "" + title: "Yes" + - id: struct-a-data-monste-1746242989 + href: "" + hreflang: "" + title: "" + text: + - text: OID + id: oid + - text: date + id: date + - text: username + id: username + - text: customer + id: customer + - text: zipcode + id: zipcode + - text: city + id: city + - text: country + id: country + - text: street + id: street + - text: order state + id: order-state + - text: workflow state + id: workflow-state + - text: total + id: total + - text: company + id: company + - text: channel order number + id: channel-order-number + - text: resubmissionDate + id: resubmission-date + - text: payment type + id: payment-type + translations: + - id: the-translation + type: application/json + translations: + key1: translation1 + key2: + other: translation2 + key3: + other: translation3 + key5: translation4 + modifications: + remove: [] + add: [] + attributes: [] diff --git a/examples/example4/template/test.html b/examples/example4/template/test.html new file mode 100644 index 0000000000000000000000000000000000000000..4c239f9dcc27309c8333ba32525a7a565dcf55e5 --- /dev/null +++ b/examples/example4/template/test.html @@ -0,0 +1,106 @@ +<!DOCTYPE html><html lang="en" data-attributes="lang path:lang"><head> + <style> + *:not(:defined) { + visibility: hidden; + } + </style> + + <meta charset="utf-8"/> + <meta name="viewport" content="width=device-width, initial-scale=1"/> + + <meta name="robots" content="noindex"/> + + <link rel="icon" type="image/x-icon" href="/asset/icon/favicon.svg"/> + <meta name="theme-color" content="#c10000"/> + <link rel="apple-touch-icon" sizes="180x180" href="/asset/icon/apple-touch-icon.png"/> + <link rel="icon" type="image/png" sizes="32x32" href="/asset/icon/favicon-32x32.png"/> + <link rel="icon" type="image/png" sizes="16x16" href="/asset/icon/favicon-16x16.png"/> + <link rel="mask-icon" href="/asset/icon/safari-pinned-tab.svg" color="#fd1d1d"/> + <meta name="msapplication-TileColor" content="#fd1d1d"/> + <meta name="msapplication-TileImage" content="/asset/icon/mstile-144x144.png"/> + + <title data-replace="path:title">Bad Request</title> + <meta name="description" content="The request was malformed or invalid." data-attributes="content path:meta.description"/> + <meta name="author" content="schukai GmbH" data-attributes="content path:meta.author"/> + + <link rel="icon" href="/favicon.ico"/> + <link rel="icon" href="/favicon.svg" type="image/svg+xml"/> + <link rel="apple-touch-icon" href="/apple-touch-icon.png"/> + + <script src="/script/main.mjs" type="module"></script> + + <script type="application/json" data-monster-role="translations" data-bob-reference="the-translation" data-replace="path:translations.the-translation.content"> + { + "key1": "translation1", + "key2": { + "other": "translation2" + }, + "key3": { + "other": "translation3" + }, + "key5": "translation4" + } + </script> + </head> + + <body> + <header> + <div class="gradient"></div> + </header> + + <monster-state> + <a href="mmmm" data-attributes="href path:anchors.mmmm.href,title path:anchors.mmmm.title,hreflang path:anchors.mmmm.hreflang" data-bob-reference="mmmm"><img width="16" height="16" alt="tick" title="yes" src="data:image/gif;base64,R0lGODdhEAAQAMwAAPj7+FmhUYjNfGuxYYDJdYTIeanOpT+DOTuANXi/bGOrWj6CONzv2sPjv2Cm + V1unU4zPgI/Sg6DJnJ3ImTh8Mtbs00aNP1CZSGy0YqLEn47RgXW8amasW7XWsmmvX2iuXiwAAAAAEAAQAAAFVyAgjmRpnihqGCkpDQ + PbGkNUOFk6DZqgHCNGg2T4QAQBoIiRSAwBE4VA4FACKgkB5NGReASFZEmxsQ0whPDi9BiACYQAInXhwOUtgCUQoORFCGt/g4QAIQA7" id="tickyesdata-image-gi-4013311193" data-bob-reference="tickyesdata-image-gi-3753669760" data-attributes="src path:content.tickyesdata-image-gi-3753669760.src,alt path:content.tickyesdata-image-gi-3753669760.alt,title path:content.tickyesdata-image-gi-3753669760.title"/></a> + <h1 class="deco"><span data-bob-reference="bad-request" data-replace-self="path:text.bad-request.text">Bad Request</span></h1> + <p><span data-bob-reference="the-request-was-inco-2640993422" data-replace-self="path:text.the-request-was-inco-2640993422.text">The request was incorrect, the server could not process it.</span></p> + <p></p> + + <a href="mmmm" data-attributes="href path:anchors.mmmm.href,title path:anchors.mmmm.title,hreflang path:anchors.mmmm.hreflang" data-bob-reference="mmmm"><span data-bob-reference="gurke" data-replace-self="path:text.gurke.text">GURKE</span></a> + + <div class="infobox"> + <div> + <ul> + <li><span data-bob-reference="try-submitting-your" data-replace-self="path:text.try-submitting-your.text"> + Try submitting your</span><a href="/a.html" title="Yes" id="yes-a-html" data-attributes="href path:anchors.yes-a-html.href,title path:anchors.yes-a-html.title,hreflang path:anchors.yes-a-html.hreflang" data-bob-reference="yes-a-html"><span data-bob-reference="request" data-replace-self="path:text.request.text">request</span></a><span data-bob-reference="again-sometimes-this-2086042570" data-replace-self="path:text.again-sometimes-this-2086042570.text"> + again (sometimes this helps). + </span></li> + <li><span data-bob-reference="contact-support-if-y-3404332025" data-replace-self="path:text.contact-support-if-y-3404332025.text">Contact support if you continue to have problems.</span></li> + + <li><span data-bob-reference="if-you-received-this-423958995" data-replace-self="path:text.if-you-received-this-423958995.text"> + If you received this message as a result of a request to the + server API, then check the structure against the documentation. + </span></li> + </ul> + + <p><span data-bob-reference="you-can-try-the-foll-3363859033" data-replace-self="path:text.you-can-try-the-foll-3363859033.text">You can try the following steps:</span></p> + <p><span data-bob-reference="you-can-try-the-foll-3363859033" data-replace-self="path:text.you-can-try-the-foll-3363859033.text">You can try the following steps:</span></p> + </div> + </div> + </monster-state> + + <monster-datatable id="datatable-order-list" data-monster-datasource-selector="#orderListDatasource"> + <template id="datatable-order-list-row"> + <div data-monster-head="OID" data-monster-mode="fixed" data-monster-sortable="oid" data-monster-grid-template="0.5fr" data-bob-reference="oid" data-attributes="data-monster-head path:text.oid.text"> + <a data-monster-attributes="href path:datatable-order-list-row.oid | tostring | prefix:/app/commerce/order-detail?oid=" data-monster-replace="path:datatable-order-list-row.oid" data-attributes="href path:anchors.struct-a-data-monste-1746242989.href,title path:anchors.struct-a-data-monste-1746242989.title,hreflang path:anchors.struct-a-data-monste-1746242989.hreflang" data-bob-reference="struct-a-data-monste-1746242989"></a> + </div> + <div data-monster-head="date" data-monster-sortable="orderDate" data-monster-replace="path:datatable-order-list-row.orderDate | datetimeformat" data-bob-reference="date" data-attributes="data-monster-head path:text.date.text"></div> + <div data-monster-head="username" data-monster-mode="hidden" data-monster-replace="path:datatable-order-list-row.userName" data-bob-reference="username" data-attributes="data-monster-head path:text.username.text"></div> + <div data-monster-head="customer" data-bob-reference="customer" data-attributes="data-monster-head path:text.customer.text">auto</div> + <div data-monster-head="zipcode" data-monster-replace="path:datatable-order-list-row.deliveryAddressZipcode" data-bob-reference="zipcode" data-attributes="data-monster-head path:text.zipcode.text"></div> + <div data-monster-head="city" data-monster-replace="path:datatable-order-list-row.deliveryAddressCity" data-bob-reference="city" data-attributes="data-monster-head path:text.city.text"></div> + <div data-monster-head="city" data-monster-replace="path:datatable-order-list-row.deliveryAddressCity" data-bob-reference="city" data-attributes="data-monster-head path:text.city.text"></div> + <div data-monster-head="country" data-monster-replace="path:datatable-order-list-row.deliveryAddressCountry | prefix:country_ | i18n" data-bob-reference="country" data-attributes="data-monster-head path:text.country.text"></div> + <div data-monster-head="street" data-monster-mode="hidden" data-monster-replace="path:datatable-order-list-row.deliveryAddressAddress1" data-bob-reference="street" data-attributes="data-monster-head path:text.street.text"></div> + <div data-monster-head="order state" data-monster-align="end" data-bob-reference="order-state" data-attributes="data-monster-head path:text.order-state.text"></div> + <div data-monster-head="workflow state" data-monster-align="end" data-monster-replace="path:datatable-order-list-row.workflowState" data-bob-reference="workflow-state" data-attributes="data-monster-head path:text.workflow-state.text"></div> + <div data-monster-head="total" data-monster-align="end" data-bob-reference="total" data-attributes="data-monster-head path:text.total.text"></div> + <div data-monster-head="company" data-monster-grid-template="0.8fr" data-monster-replace="path:datatable-order-list-row.companySHID | tostring | prefix:<img src='/alvine/upload/company/files/ | suffix:/shopicon.gif'>" data-bob-reference="company" data-attributes="data-monster-head path:text.company.text"></div> + <div data-monster-head="channel order number" data-monster-replace="path:datatable-order-list-row.channelOrderID" data-bob-reference="channel-order-number" data-attributes="data-monster-head path:text.channel-order-number.text"></div> + <div data-monster-head="resubmissionDate" data-monster-mode="hidden" data-bob-reference="resubmission-date" data-attributes="data-monster-head path:text.resubmission-date.text"></div> + <div data-monster-head="payment type" data-monster-replace="path:datatable-order-list-row.localStrings.paymentType" data-bob-reference="payment-type" data-attributes="data-monster-head path:text.payment-type.text"></div> + </template> + </monster-datatable> + + +</body></html> \ No newline at end of file diff --git a/source/template/prepare.go b/source/template/prepare.go index b5d09495103e8074e943225941b17da073b2b7ec..4f55c2b98c7cf1a8fa3af9ca1b2f1a8a06c6bc76 100644 --- a/source/template/prepare.go +++ b/source/template/prepare.go @@ -173,7 +173,7 @@ func prepareAnchors(node *html.Node, storage *types.PageData) { k := title + hreflang + href if k == "" { - log.Warn("The anchor '" + logContent + "' has no title, hreflang and href attribute! Will use the content of the anchor as key.") + log.Warn("The anchor '" + logContent + "' has no title, hreflang and href attribute! Will use the content of the anchor as a key.") k = logContent } @@ -422,6 +422,12 @@ func handleTextNode(n *html.Node, storage *types.PageData) { if n.Parent != nil { if n.Parent.Type == html.ElementNode { + + // if span and has constants.DataBobReferenceAttributeKey, ignore + if n.Parent.Data == "span" && util.HasAttribute(n.Parent.Attr, constants.DataBobReferenceAttributeKey) { + return + } + if util.HasAttribute(n.Parent.Attr, "data-monster-head") { return } @@ -431,9 +437,9 @@ func handleTextNode(n *html.Node, storage *types.PageData) { id, err := util.BuildTextKey(content) if err != nil || id == "" { id = util.GetNextId() - log.Warn("Could not build text key for: '" + logContent + "', using ID: " + id + " instead.") + log.Warn("Could not build a text key for: '" + logContent + "', using ID: " + id + " instead.") } else { - log.Info("Create text key: " + id) + log.Info("Create a text key: " + id) } // check if id is already in use