[TIL] 211228

Lee SyongΒ·2021λ…„ 12μ›” 28일
0

TIL

λͺ©λ‘ 보기
132/204
post-thumbnail

πŸ“ 였늘 ν•œ 것

  1. 볡슡 - SCSS (ν”„λ‘œν•„ 이미지 / ν…μŠ€νŠΈ 쀄 λ°”κΏˆ, λ§μ€„μž„ν‘œ λ“±)

πŸ“š 배운 것 (볡슡)

μ‹€μ œ μ½”λ“œλŠ” github에 올림(wetube_v2)
ν”„λ‘œν•„ 이미지(avatar) / search / profile / edit / shared.scss

7. STYLES

  • [TIL] 211209
    • populate 쀑첩 μ‚¬μš©
    • form에 font-awesome μ•„μ΄μ½˜ λ„£κΈ°
    • ν…μŠ€νŠΈ 수직 쀑앙 μ •λ ¬
    • ν”„λ‘œν•„ 이미지(avatar) λΉ„μœ¨μ— 맞좰 μ›ν˜•μœΌλ‘œ 자λ₯΄κΈ°
    • μ—¬λŸ¬ 쀄 λ¬Έμžμ—΄ 쀄 λ°”κΎΈκ³  숨기기 (μΆ”κ°€)

πŸ’‘ populate 쀑첩 μ‚¬μš©

// userController.js
export const see = async (req, res) => {
  const { id } = req.params;
  const user = await User.findById(id).populate({
    path: "videos",
    // populate 쀑첩 μ‚¬μš©
    populate: {
      path: "owner",
      model: "User",
    },
    // λ‚΄λ¦Όμ°¨μˆœ μ •λ ¬
    options: {
      sort: { createdAt: "desc" },
    },
  });
  if (!user) {
    return res.status(404).render("404", { pageTitle: "User not found" });
  }
  return res.render("profile", { pageTitle: user.name, user });
};

πŸ’‘ form에 font-awesome μ•„μ΄μ½˜ λ„£κΈ°

  • input(type="submit") λŒ€μ‹ μ— button(type="submit")을 넣어쀬닀.
//- search.pug

div.form-container.form-container__search
  form.search-form(method="GET")
    input(name="keyword", placeholder="검색", required)
    button.search-button
      i.fas.fa-search
  • position: absolute λ₯Ό μ΄μš©ν•΄ μœ„μΉ˜λ₯Ό μž‘μ•„μ€¬λ‹€.
// search.scss

.form-container__search {
  border-style: none;
  box-shadow: none;
  margin-bottom: 4rem;
  padding: 0;
}

.search-form {
  position: relative;
  .search-button {
    border-style: none;
    background-color: transparent;
    color: $color-white;
    font-size: $font-regular;
    padding: 0;
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    cursor: pointer;
  }
}

πŸ’‘ ν”„λ‘œν•„ 이미지(avatar) λΉ„μœ¨μ— 맞좰 μ›ν˜•μœΌλ‘œ 자λ₯΄κΈ°

  • background-image 속성을 μ΄μš©ν–ˆλ‹€. loggedInUser.avatarUrl (header.pug) / user.avatarUrl (profile.pug) / video.owner.avatarUrl (video.pug) 의 값을 가져와야 ν•˜κΈ° λ•Œλ¬Έμ— background-image 속성은 pug νŒŒμΌμ—μ„œ 인라인 μŠ€νƒ€μΌ(inline style) ν˜•μ‹μœΌλ‘œ μΆ”κ°€ν–ˆλ‹€.
  • avatarUrl이 μ—†λŠ” κ²½μš°λŠ” 일단 μž„μ‹œλ‘œ 이λͺ¨ν‹°μ½˜μ„ 넣어쀬닀. 배포 후에 AWS S3μ—μ„œ κΈ°λ³Έ 이미지λ₯Ό κ°€μ Έμ˜€λ„λ‘ μˆ˜μ •ν•  것이닀.
//- header.pug

a(href=`/users/${loggedInUser._id}`)
  if !loggedInUser.avatarUrl
    span.profile-img 😎
  else if loggedInUser.socialOnly
    div.profile-img(style=`background-image: url("${loggedInUser.avatarUrl}");`)
  else
    div.profile-img(style=`background-image: url("/${loggedInUser.avatarUrl}");`)
// shared.scss

.profile-img {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
}

cf. 이전에 썼던 방법

div.profile-outer-box
  div.profile-inner-box
    a(href=`/users/${loggedInUser._id}`)
      if loggedInUser.socialOnly 
        img(src=loggedInUser.avatarUrl, crossorigin).profile-img
      else
        img(src=loggedInUser.avatarUrl).profile-img
.profile-outer-box {
  width: 60px;
  .profile-inner-box {
    padding-top: 100%;
    overflow: hidden;
    position: relative;
    border-radius: 50%;
    .profile-img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
  }
}

λ‹Ήμž₯ κ°–λ‹€λ²„λ¦¬μž. padding-top: % κ΄€λ ¨ν•΄μ„œ μ•Œκ³  μžˆμ–΄μ•Ό ν•˜κΈ΄ ν•˜μ§€λ§Œ κ·Έλž˜λ„ λ‹Ήμž₯ κ°–λ‹€λ²„λ¦¬μž.

πŸ’‘ μ—¬λŸ¬ 쀄 λ¬Έμžμ—΄ 쀄 λ°”κΎΈκ³  숨기기

CSS / CSS둜 λ¬Έμžμ—΄ 자λ₯΄κΈ° - ν•œ 쀄인 경우, μ—¬λŸ¬ 쀄인 경우,
word-break 속성과 word-wrap 속성 μ•Œμ•„λ³΄κΈ°,
word-wrap μ€„λ°”κΏˆ 속성(normal, break-word) μ°Έκ³ 

//- video.scss

div.video-mixin__info
  a(href=`/videos/${video.id}`).video-mixin__title=video.title
// video.scss

.video-mixin__info {
  overflow: hidden; // μ˜†μœΌλ‘œ λ„˜μΉ˜λŠ” λΆ€λΆ„ μˆ¨κΉ€
  .video-mixin__title {
    overflow: hidden; // λ°‘μœΌλ‘œ λ„˜μΉ˜λŠ” λΆ€λΆ„ μˆ¨κΉ€
    line-height: 1.4rem; // 1쀄 높이 μ„€μ •
    max-height: 2.8rem; // 2쀄 보여주고 μ‹ΆμœΌλ‹ˆκΉŒ 1.4 * 2 (height μ‚¬μš© x)
    word-break: break-all; // 음절 λ‹¨μœ„μ—μ„œ 쀄 λ°”κΏˆ (μ˜μ–΄)
    word-wrap: break-word; // 음절 λ‹¨μœ„μ—μ„œ 쀄 λ°”κΏˆ (ν•œμ€‘μΌ μ–Έμ–΄)
    // μ΄ν•˜ 3쀄 μ½”λ“œλŠ” Chrome 버그(쀄 λ°”κΏˆ μ•ˆλ¨) λ•Œλ¬Έμ— 좔가함
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    font-size: $font-regular;
  }
}

처음 ν•  λ•Œ ꡉμž₯히 μ–΄λ €μ› λ˜ 파트인데 μƒˆλ‘­κ²Œ λ‹€λ₯Έ λ°©λ²•λ“€λ‘œ λ‹€μ‹œ ν•΄λ³΄λ©΄μ„œ 정리가 쑰금 된 κ±° κ°™λ‹€.


✨ 내일 ν•  것

  1. 볡슡 κ³„μ†ν•˜κΈ° - video player
profile
λŠ₯λ™μ μœΌλ‘œ μ‚΄μž, ν–‰λ³΅ν•˜κ²ŒπŸ˜

0개의 λŒ“κΈ€