Git Product home page Git Product logo

carbon-design-system / carbon-for-ibm-dotcom-web-components-template Goto Github PK

View Code? Open in Web Editor NEW
11.0 11.0 12.0 4.42 MB

This is an HTML Template utilizing Carbon for IBM.com Web Components. It contains a basic WebPack setup using Handlebars for page management, which includes the dds-dotcom-shell, along with other various patterns and components available in Carbon for IBM.com.

License: Apache License 2.0

JavaScript 41.23% SCSS 1.36% Handlebars 57.41%
webcomponents carbon carbon-design-system handlebars javascript hacktoberfest

carbon-for-ibm-dotcom-web-components-template's Introduction

Carbon for IBM.com Web Components HTML Template

Table of Contents

Overview

This is an HTML Template utilizing Carbon for IBM.com Web Components. It contains a basic WebPack setup using Handlebars for page management, which includes the dds-dotcom-shell, along with other various patterns and components available in Carbon for IBM.com.

Getting Started

Get the code by clicking Use this template, or clone this repo using git:

git clone https://github.com/carbon-design-system/carbon-for-ibm-dotcom-web-components-template.git

Once cloned, go to the project directory to install dependencies and build the project

$ yarn && yarn build

In order to enable features like Right-to-Left (RTL), you will have to set environment variables in a .env file. Please see .env.example.

ALTLANG_ROOT_PATH=<Sets the root path for language alternative urls, default is '/' >
LANG_DEFAULT=<Sets the default language, default is 'en-us'>

Then start the application:

$ yarn start

To export to a static site, run the following:

$ yarn build

Then the contents of the dist folder can be uploaded to your production environment.

Creating new pages

This repo contains an example page that can be easily modified and expanded upon. In order to get started, navigate to src/pages/home/home.hbs and you can start editing the Handlebars template as you would regular HTML.

If you'd like to create more pages, you're welcome to copy the example directory into one of your own. However, you'll have to edit the file in src/pages.js to include this new page. Note the translationKey, which is the string responsible to fetch the translated values to be used in the page -- more on that later.

const pages = [
  // other pages
  {
    output: './example/index.html',
    content: {
      title: 'Example page',
      description: 'An example page',
    },
    chunks: ['example'],
    chunkEntry: {
      'example': './src/pages/example/example.js',
    },
    template: './src/pages/example/example.hbs',
    translationKey: 'example'
  },
]

Page Language / i18n Support

This template handles page language functionality, where the available language template strings are defined in src/locales/[language-locale]/*.json, where the name of each json file is the corresponding page translation key.

For example, the homepage for en-us would live under /src/locales/en-us/home.json with the following content:

{
  "leadspace_title": "Lead space title",
  "leadspace_copy": "Use this area for a short line of copy to support the title",
  "content_block_mixed_heading": "Content Block - Mixed Groups",
  "content_block_segmented_heading": "Content Block - Segmented",
  "content_block_simple_heading": "Content Block - Simple",
  "content_block_media_heading": "Content Block - With Media"
}

To create additional languages, create a new folder for the language/locale, then generate the corresponding page data.

For example, creating a corresponding home page data for fr-ca, the file /src/locales/fr-ca/home.json would be created with the following content:

{
  "leadspace_title": "Titre de l'espace principal",
  "leadspace_copy": "Utilisez cette zone pour une courte ligne de copie pour soutenir le titre",
  "content_block_mixed_heading": "Bloc de contenu - Groupes mixtes",
  "content_block_segmented_heading": "Bloc de contenu - Segmenté",
  "content_block_simple_heading": "Bloc de contenu - Simple",
  "content_block_media_heading": "Bloc de contenu - Avec média"
}

Once you run yarn build, the exported files will be found in the dist folder, and each locale will also output its own folder containing all of the translated pages from the original template.

Urls for the above examples would output as:

  • /en-us/index.html
  • /fr-ca/index.html

Note, if there is only one language folder in /src/locales, then the output will not generate the corresponding language/locale folders, and would generate in the root distribution folder:

  • /index.html

SASS compilation and carbon-components

There may be times pathing errors are encountered when importing certain

stylesheets (like carbon-components). We're working hard to fix these, but in the meantime you can add the following to your .env file to resolve:

SASS_PATH=node_modules:src

Note: For Windows, the syntax is slightly different

SASS_PATH=./node_modules;./src

Right-to-Left (RTL)

Right-to-left rendering is supported, and is automatically set for the following language codes:

  • ar (Arabic)

For example, creating Arabic pages for Saudi Arabia would be auto-generated in RTL for any locale content under /src/locales/ar-sa.

Things to Note

If building an IBM.com page, there are items that need to be included which can be viewed here:

Building for IBM.com

Digital Data Object

The Digital Data Object (DDO) is a flexible, customizable collection of metadata that also provides tools and services such as live chat and analytics to page authors. You can find more details on Building for IBM.com.

The template has a placeholder DDO you can define located in src/layouts/base.hbs. Example values shown below:

<script>
  digitalData = {
    page: {
      category: {
        primaryCategory: '' // e.g. SB03
      },
      pageInfo: {
        effectiveDate: '', // e.g. 2014-11-19
        expiryDate: '', // e.g. 2017-11-19
        language: '{{i18n "base_lang"}}', // e.g. en-US, automatically updated
        publishDate: '', // e.g. 2014-11-19
        publisher: '', // e.g. IBM Corporation
        version: 'Carbon for IBM.com',
        ibm: {
          contentDelivery: '', // e.g. ECM/Filegen
          contentProducer: '', // e.g. ECM/IConS Adopter 34 - GS83J2343G3H3ERG - 11/19/2014 05:14:02 PM
          country: '{{i18n "base_country"}}', // e.g. US, automatically updated
          industry: '', // e.g. B,U
          owner: '', // e.g. Some Person/City/IBM
          siteID: '', // e.g. MySiteID
          subject: '', // e.g. SW492
          type: '' // e.g CT305
        }
      }
    }
  };
</script>

Meta Tags and Analytics

The template already renders the required meta tags and IBM.com analytics script that are required for IBM.com websites.

They are located in src/layouts/base.hbs.These can be adjusted/removed to fit your project and needs.

Meta Tags:

<meta charset="UTF-8" />

<link rel="icon" href="//www.ibm.com/favicon.ico" />

<meta name="dcterms.date" content="YYYY-MM-DD" />
<meta name="dcterms.rights" content="© Copyright IBM Corp. 2021" />
<meta name="geo.country" content="US" />
<meta name="robots" content="index,follow" />

IBM.com Tag Management and Site Analytics Script

<!-- IBM Tag Management and Site Analytics -->

<script
  src="//1.www.s81c.com/common/stats/ibm-common.js"
  async="async"
></script>

Carbon Theme Zoning Classes

By default, the base template offers a reference to the Carbon for IBM.com theme CDN style helper that allows you to easily define the theme of a particular component using Carbon theme utility classes.

Available classes

Theme Class name
white .dds-theme-zone-white
g10 .dds-theme-zone-g10
g90 .dds-theme-zone-g90
g100 .dds-theme-zone-g100

Example usage

Leadspace component using g100 theme.

<dds-leadspace size="medium" class="dds-theme-zone-g100">
  <dds-leadspace-heading>LeadSpace title</dds-leadspace-heading>
  LeadSpace copy
</dds-leadspace>

This is an optional feature, therefore if you decided to use the import method instead of leveraging from the existing CDN artifact, you can simply remove this line from the base.hbs file.

<link
  rel="stylesheet"
  href="https://1.www.s81c.com/common/carbon-for-ibm-dotcom/tag/v1/latest/themes.css"
/>

Upgrading from the Template

To pull latest changes from the Carbon for IBM.com HTML template, this repo can be added as a remote to your application repository:

git remote add template https://github.com/carbon-design-system/carbon-for-ibm-dotcom-web-components-template.git

Then run git fetch to update the changes:

git fetch --all

And finally merge changes in:

git merge template/main

carbon-for-ibm-dotcom-web-components-template's People

Contributors

ariellalgilmore avatar dependabot[bot] avatar emyarod avatar ibmdotcom-bot avatar ignaciobecerra avatar jeffchew avatar proeung avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

carbon-for-ibm-dotcom-web-components-template's Issues

[Web Components Template] Automatically build and configure pages that use RTL

The problem

Right now, there is a flag for turning on or off RTL. This would be much better if both artifacts are generated on build, and then they are used depending on the detected language.

The solution

For example, if there is an Arabic language page, it should automatically create the RTL artifact, and add <html dir="rtl"> without the developer having to set any environment variables. This can most likely be an addition to the webpack logic.

Additional information

  • For now, should target Arabic for this

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/codeql-analysis.yml
  • actions/checkout v2
  • github/codeql-action v1
  • github/codeql-action v1
  • github/codeql-action v1
npm
package.json
  • @carbon/grid ^10.15.0
  • @carbon/ibmdotcom-web-components ^1.29.0
  • @carbon/type ^10.13.0
  • carbon-web-components ^1.7.1
  • lit-element ^2.4.0
  • lit-html ^1.3.0
  • @actions/core ^1.6.0
  • @babel/core ^7.16.0
  • @babel/preset-env ^7.16.0
  • @commitlint/cli ^16.0.0
  • @commitlint/config-conventional ^16.0.0
  • @webpack-cli/serve ^1.5.2
  • autoprefixer ^10.0.0
  • babel-loader ^8.2.3
  • browser-sync ^2.26.3
  • browser-sync-webpack-plugin ^2.2.2
  • copy-webpack-plugin ^6.4.1
  • css-loader ^1.0.1
  • dotenv ^14.0.0
  • eslint ^8.0.0
  • eslint-plugin-jsdoc ^37.0.0
  • eslint-webpack-plugin ^3.1.1
  • file-loader ^6.0.0
  • handlebars ^4.7.7
  • handlebars-loader ^1.7.0
  • html-webpack-plugin ^4.5.1
  • husky ^7.0.0
  • lint-staged ^12.0.0
  • mini-css-extract-plugin ^0.12.0
  • node-sass ^6.0.1
  • postcss ^8.3.6
  • postcss-loader 4.3.0
  • postcss-selector-parser ^6.0.6
  • prettier ^2.1.2
  • rtlcss ^2.6.0
  • sass-loader ^10.2.0
  • stylelint ^14.0.0
  • terser-webpack-plugin ^4.1.0
  • webpack ^4.46.0
  • webpack-cli ^4.8.0
  • webpack-dev-server ^4.1.0
packages/eslint-config-ibmdotcom/package.json
  • @babel/eslint-parser ^7.16.5
  • eslint-config-airbnb ^19.0.0
  • eslint-config-airbnb-base ^15.0.0
  • eslint-config-prettier ^8.0.0
  • eslint-plugin-import ^2.17.3
  • eslint-plugin-jsdoc ^37.0.0
  • eslint-plugin-prettier ^4.0.0
  • eslint-restricted-globals ^0.2.0
  • eslint ^8.0.0
packages/stylelint-config-ibmdotcom/package.json
  • stylelint-config-prettier ^9.0.0
  • stylelint-prettier ^2.0.0
  • stylelint-scss ^4.0.0
  • stylelint ^14.0.0
  • stylelint ^14.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

[Web Components Template] Include Carbon Theme Zoning Classes CDN

Summary

<dds-leadspace size="medium" class="dds-theme-zone-g90">
      <dds-leadspace-heading>LeadSpace title</dds-leadspace-heading>
      LeadSpace copy
</dds-leadspace>  

Relevant information

  • Add the CDN link to the base page.
  • Add documentation on how to use it.
  • Add documentation on instructions for removal is not using it.

[Web Components template] Properly set the locale/language based on url

Detailed description

Describe in detail the issue you're having.

The current setup is fetching the language/locale the way that the test app is configured, which does not match how language pages are generated in the template.

Also, the altlang urls are not configured correctly either and need to be updated. This could possibly be set dynamically based on the available language files (see #4 )

Is this a feature request (new component, new icon), a bug, or a general
issue?

bug

Is this issue related to a specific component?

Base page

What did you expect to happen? What happened instead? What would you like to
see changed?

Properly set the DDO based on the template url pattern

Should also default to en-us if no languages are set.

[Web Components Template] Update config to automate language page creation

The problem

Translation data is currently captured in separate json files. In addition, the language/locale folders are also generated manually within the webpack config. This is overhead configuration that could lead to misconfigurations, as well as additional management for adopters of this template.

The solution

This should be updated so that the language/local folders are auto-generated based on the existence of the language files.

Additional information

  • We should also account for cases where languages are not necessary, so that the language folders aren't generated if the translation files are empty, or perhaps a configuration that would disable this feature and only take in the data from a single set of i18n data.
  • This template would be used by adopters to create a new repo to build their own experience.

[Web Components Template] Enable base stylesheet and page specific assets directory that houses SCSS partial and images

The problem

  • While developing the landing page for Watson Orchestrate, we realized that there are additional styles that are needed in order for us to assemble a landing page that matches the design.
  • Here's an example of the added styles that we've implemented for the Watson Orchestrate Landing page (https://github.ibm.com/Putra-Bonaccorsi/web-components-for-ei/blob/master/src/assets/scss/app.scss).
  • This feature allows adopters to easily build and contribute out boilerplate templates that can be used within the ibm.com EI content ecosystem and makes this project the go-to place to adopt landing page designs (eg. Explainer, Solution, etc) for different products.

The solution

  • Enable a /assets directory within each template page (eg. /src/pages/page2/assets)
  • Adjust the current Webpack configs to watch, live-reload, and build the assets.

Additional information

cc: @jwitkowski79

Yarn start builds but throws in an error with "base_lang"

Yarn start builds but throws in an error with "base_lang"

Detailed description

Not a blocker, but on Windows 10 Powershell, when executing $yarn start I get this error message:
`ERROR in Template execution failed: TypeError: Cannot read property 'base_lang' of undefined

ERROR in TypeError: Cannot read property 'base_lang' of undefined

  • handlebars.js:9 Object.eval
    webpack-internal:///./config/handlebars.js:9:22

  • wrapHelper.js:15 Object.wrapper
    [.]/[handlebars]/dist/cjs/handlebars/internal/wrapHelper.js:15:19

  • base.hbs:147 Object.main
    webpack-internal:///./src/layouts/base.hbs:147:98

  • runtime.js:208 main
    [.]/[handlebars]/dist/cjs/handlebars/runtime.js:208:32

  • runtime.js:212 ret
    [.]/[handlebars]/dist/cjs/handlebars/runtime.js:212:12

  • runtime.js:334 Object.invokePartial
    [.]/[handlebars]/dist/cjs/handlebars/runtime.js:334:12

  • runtime.js:84 Object.invokePartialWrapper [as invokePartial]
    [.]/[handlebars]/dist/cjs/handlebars/runtime.js:84:39

  • app.hbs:185 Object.main
    [.]/[html-webpack-plugin]/lib/loader.js!./src/pages/app/app.hbs:185:31

  • runtime.js:208 main
    [.]/[handlebars]/dist/cjs/handlebars/runtime.js:208:32

  • runtime.js:212 ret
    [.]/[handlebars]/dist/cjs/handlebars/runtime.js:212:12`

What browser are you working in?
Chromium: 92.0.4515.131 (Official Build) (64-bit)

Steps to reproduce the issue

  1. Step one - run $yarn start on windows 10, using powershell

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.